source: trunk/kernel/libk/remote_queuelock.h @ 679

Last change on this file since 679 was 666, checked in by alain, 4 years ago

Cosmetic.

File size: 4.9 KB
RevLine 
[563]1/*
2 * remote_queuelock.h: remote kernel lock with waiting queue definition.
3 *
4 * Authors  Alain Greiner (2016,2017,2018)
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-kernel; 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_QUEUELOCK_H_
25#define _REMOTE_QUEUELOCK_H_
26
27#include <kernel_config.h>
28#include <hal_kernel_types.h>
29#include <remote_busylock.h>
30#include <xlist.h>
31
32/*******************************************************************************************
33 * This synchronisation object sequencializes concurrent read or write accesses to a
34 * globally shared object located in any cluster, made by thread(s) running in any cluster.
35 * This lock has only two states: taken or free.
36 * When the lock has been taken by another thread T', the thread T executing the
37 * queuelock_acquire() function blocks and deschedules, after registering in the waiting
38 * queue rooted in lock descriptor. The first thread in the waiting queue will be unblocked
39 * by the owner thread executing the queuelock_release() function.
40 * To handle concurrent accesses between a thread T executing the acquire() function
41 * and a thread T' executing the release() function, the "remote_queuelock" is protected
42 * by a "remote_busylock" used by these two access functions.
43 ******************************************************************************************/
44 
45
46/*******************************************************************************************
47 * This structure defines a remote_queuelock.
48 ******************************************************************************************/
49
50typedef struct remote_queuelock_s
51{
52    remote_busylock_t   lock;               /*! protect atomic access to remote_queuelock */
53        volatile uint32_t   taken;              /*! state : free if zero / taken if non zero  */
54    xlist_entry_t       xroot;              /*! root of xlist of waiting threads          */
55}
56remote_queuelock_t;
57
58/*******************************************************************************************
59 * This function initializes a local remote_queuelock in free state.
[666]60 * The <type> argument defines the lock usage and is only used for debug.
[563]61 * This type is actually stored in the associated busylock descriptor.
62 *******************************************************************************************
63 * @ lock_xp   : extended pointer on remote_queuelock.
64 * @ type      : lock usage for debug.
65******************************************************************************************/
66inline void remote_queuelock_init( xptr_t   lock_xp,
67                                   uint32_t type );
68
69/*******************************************************************************************
70 * This blocking function acquires a remote_queuelock.
71 * The calling thread and the lock can be in different clusters.
72 * It uses the remote_busylock to atomically access/update the remote_queuelock state.
73 * If the lock is already taken, the calling thread atomically registers in the xlist
74 * of waiting threads (rooted in the lock descriptor), block and deschedule.
75 * It increments the calling thread remote_locks counter when the lock has been taken.
76 * It optionally update the <owner_xp> and <xlist> debug fields.
77 *******************************************************************************************
78 * @ lock_xp   : extended pointer on remote_queuelock.
79 ******************************************************************************************/
80void remote_queuelock_acquire( xptr_t  lock_xp );
81
82/*******************************************************************************************
83 * This function releases a remote_queuelock.
84 * The calling thread and the lock can be in different clusters.
85 * It uses the remote_busylock to atomically access/update the remote_queuelock state.
86 * If the xlist of waiting threads is not empty, the first waiting thread is unblocked.
87 * It decrements the calling thread remote_locks counter when the lock has been released.
88 * It optionally update the <owner_xp> and <xlist> debug fields.
89 *******************************************************************************************
90 * @ lock_xp   : extended pointer on remote_queuelock.
91 ******************************************************************************************/
92void remote_queuelock_release( xptr_t lock_xp );
93
94
95#endif  /* _REMOTE_QUEUELOCK_H_ */
Note: See TracBrowser for help on using the repository browser.