source: trunk/kernel/libk/remote_spinlock.h @ 521

Last change on this file since 521 was 460, checked in by viala@…, 6 years ago

Typo: remote_spinlock_lock/unlock decrement/increment locks

File size: 5.3 KB
RevLine 
[1]1/*
2 * remote_spinlock.h - kernel remote spinlock definition.
3 *
[436]4 * Author  Alain Greiner (2016,2017,2018)
[1]5 *
6 * Copyright (c) UPMC Sorbonne Universites
7 *
8 * This file is part of ALMOS-MKH.
9 *
10 * ALMOS-MKH is free software; you can redistribute it and/or modify it
11 * under the terms of the GNU General Public License as published by
12 * the Free Software Foundation; version 2.0 of the License.
13 *
14 * ALMOS-MKH is distributed in the hope that it will be useful, but
15 * WITHOUT ANY WARRANTY; without even the implied warranty of
16 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
17 * General Public License for more details.
18 *
19 * You should have received a copy of the GNU General Public License
20 * along with ALMOS-MKH; if not, write to the Free Software Foundation,
21 * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
22 */
23
24#ifndef _REMOTE_SPINLOCK_H_
25#define _REMOTE_SPINLOCK_H_
26
[14]27#include <kernel_config.h>
[457]28#include <hal_kernel_types.h>
[1]29#include <xlist.h>
30
31/***************************************************************************************
32 * This structure defines a remote spinlock, that can be used to protect
33 * exclusive access to a trans-cluster shared resource. It can be taken by any
[409]34 * thread running in any cluster. All access functions use remote pointers.
35 * The "owner" and "list" are optionnal fields used for debug.
36 * It register the list of all remote spinlocks taken by a given thread.
[1]37 **************************************************************************************/
38
39typedef struct remote_spinlock_s
40{
41    volatile uint32_t     taken;       /*! free if 0 / taken if non zero             */
[409]42
[438]43#if DEBUG_REMOTE_SPINLOCKS
[1]44    xptr_t                owner;       /*! extended pointer on the owner thread      */
45    xlist_entry_t         list;        /*! list of all remote_lock taken by owner    */
[409]46#endif
47
[1]48} 
49remote_spinlock_t;
50
51/***************************************************************************************
52 * This function initializes a remote spinlock.
53 ***************************************************************************************
[11]54 * @ lock_xp : extended pointer on the remote spinlock
[1]55 **************************************************************************************/
[11]56void remote_spinlock_init( xptr_t   lock_xp );
[1]57
[11]58/*******************************************************************************************
59 * This blocking function uses a busy waiting strategy to lock a remote spinlock.
60 * It polls the lock and returns only when the lock has been taken.
61 * All IRQs are disabled and will keep disabled until the lock is released.
[460]62 * It increments the calling thread remote_locks count when the lock has been taken.
[11]63 *******************************************************************************************
64 * @ lock_xp    : extended pointer on the remote spinlock.
65 * @ irq_state  : buffer to save the SR state (in the calling thread stack)
66 ******************************************************************************************/
67void remote_spinlock_lock_busy( xptr_t     lock_xp,
68                                uint32_t * irq_state );
69
70/*******************************************************************************************
71 * This function releases a remote busy_waiting spinlock.
72 * It restores the CPU SR state.
[460]73 * It decrements the calling thread remote_locks count.
[11]74 *******************************************************************************************
75 * @ lock_xp    : extended pointer on remote spinlock.
76 * @ irq_state  : value to be resrored in CPU SR
77 ******************************************************************************************/
78void remote_spinlock_unlock_busy( xptr_t     lock_xp,
79                                  uint32_t   irq_state );
80
[1]81/***************************************************************************************
82 * This blocking function locks a remote spinlock.
83 * If the lock is already taken, the calling thread deschedule, and retry
84 * when it is rescheduled.
85 * It increments the calling thread locks count when the lock has been taken.
86 ***************************************************************************************
[11]87 * @ lock_xp   : extended pointer on the remote spinlock
[1]88 **************************************************************************************/
[11]89void remote_spinlock_lock( xptr_t lock_xp );
[1]90
91/***************************************************************************************
92 * This non blocking function try once to lock a remote spinlock.
93 * It increments the calling thread locks count in case of success.
94 ***************************************************************************************
[11]95 * @ lock_xp    : extended pointer on the remote spinlock
[1]96 * @ returns O if success / returns non zero if lock already taken.
97 **************************************************************************************/
[11]98error_t remote_spinlock_trylock( xptr_t  lock_xp );
[1]99
100/***************************************************************************************
101 * This function releases a remote spinlock.
[433]102 * It decrements the calling thread locks count.
[1]103 ***************************************************************************************
[11]104 * @ lock_xp    : extended pointer on the remote spinlock
[1]105 **************************************************************************************/
[11]106void remote_spinlock_unlock( xptr_t  lock_xp );
[1]107
108#endif
Note: See TracBrowser for help on using the repository browser.