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

Last change on this file since 361 was 101, checked in by alain, 7 years ago

euh...

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