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

Last change on this file since 1 was 1, checked in by alain, 8 years ago

First import

File size: 3.7 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 <almos_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    : extended pointer on the remote spinlock
51 **************************************************************************************/
52void remote_spinlock_init( xptr_t   lock );
53
54/***************************************************************************************
55 * This blocking function locks a remote spinlock.
56 * If the lock is already taken, the calling thread deschedule, and retry
57 * when it is rescheduled.
58 * It increments the calling thread locks count when the lock has been taken.
59 ***************************************************************************************
60 * @ lock    : extended pointer on the remote spinlock
61 **************************************************************************************/
62void remote_spinlock_lock( xptr_t lock );
63
64/***************************************************************************************
65 * This non blocking function try once to lock a remote spinlock.
66 * It increments the calling thread locks count in case of success.
67 ***************************************************************************************
68 * @ lock    : extended pointer on the remote spinlock
69 * @ returns O if success / returns non zero if lock already taken.
70 **************************************************************************************/
71uint32_t remote_spinlock_trylock( xptr_t lock );
72
73/***************************************************************************************
74 * This function releases a remote spinlock.
75 ***************************************************************************************
76 * @ lock    : extended pointer on the remote spinlock
77 **************************************************************************************/
78void remote_spinlock_unlock( xptr_t lock );
79
80#endif
Note: See TracBrowser for help on using the repository browser.