1 | /* |
---|
2 | * remote_rwlock.h - kernel remote_rwlock definition. |
---|
3 | * |
---|
4 | * Authors Alain Greiner (2016) |
---|
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_RWLOCK_H_ |
---|
25 | #define _REMOTE_RWLOCK_H_ |
---|
26 | |
---|
27 | #include <kernel_config.h> |
---|
28 | #include <hal_types.h> |
---|
29 | #include <xlist.h> |
---|
30 | |
---|
31 | /*************************************************************************************** |
---|
32 | * This file defines a remote kernel lock, that supports several simultaneous read |
---|
33 | * accesses, but only one write access. It implements a ticket based allocation policy. |
---|
34 | * It can be used to synchronize threads running in different clusters, because |
---|
35 | * all access functions use remote pointers. |
---|
36 | * - A reader take the lock to atomically increments the registered readers count. |
---|
37 | * Then it release the lock and access the protected structure. It atomically |
---|
38 | * decrements the readers count without taking the lock when access is completed. |
---|
39 | * - A writer take the lock and keep it, but must wait completion of all current read |
---|
40 | * accesses before starting its own access. |
---|
41 | * When the lock is taken by another thread, the new-comers use a busy waiting policy. |
---|
42 | **************************************************************************************/ |
---|
43 | |
---|
44 | typedef struct remote_rwlock_s |
---|
45 | { |
---|
46 | uint32_t ticket; /*! first free ticket index */ |
---|
47 | uint32_t current; /*! ticket index of current owner */ |
---|
48 | uint32_t count; /*! current number of reader threads */ |
---|
49 | |
---|
50 | #if CONFIG_LOCKS_DEBUG |
---|
51 | xptr_t owner; /*! extended pointer on writer thread */ |
---|
52 | xlist_entry_t list; /*! member of list of remote locks taken by owner */ |
---|
53 | #endif |
---|
54 | |
---|
55 | } |
---|
56 | remote_rwlock_t; |
---|
57 | |
---|
58 | /*************************************************************************************** |
---|
59 | * This function initializes a remote rwlock. |
---|
60 | *************************************************************************************** |
---|
61 | * @ lock_xp : extended pointer on the remote rwlock |
---|
62 | **************************************************************************************/ |
---|
63 | void remote_rwlock_init( xptr_t lock_xp ); |
---|
64 | |
---|
65 | /*************************************************************************************** |
---|
66 | * This blocking function get access to a remote rwlock for a reader. |
---|
67 | * It increments the calling thread locks count when the lock has been taken. |
---|
68 | *************************************************************************************** |
---|
69 | * @ lock_xp : extended pointer on the remote rwlock |
---|
70 | **************************************************************************************/ |
---|
71 | void remote_rwlock_rd_lock( xptr_t lock_xp ); |
---|
72 | |
---|
73 | /*************************************************************************************** |
---|
74 | * This function releases a remote rwlock for a reader. |
---|
75 | * It decrements the calling thread locks count when the lock has been released. |
---|
76 | *************************************************************************************** |
---|
77 | * @ lock_xp : extended pointer on the remote rwlock |
---|
78 | **************************************************************************************/ |
---|
79 | void remote_rwlock_rd_unlock( xptr_t lock_xp ); |
---|
80 | |
---|
81 | /*************************************************************************************** |
---|
82 | * This blocking function get access to a remote rwlock for a writer. |
---|
83 | * It increments the calling thread locks count when the lock has been taken. |
---|
84 | *************************************************************************************** |
---|
85 | * @ lock_xp : extended pointer on the remote rwlock |
---|
86 | **************************************************************************************/ |
---|
87 | void remote_rwlock_wr_lock( xptr_t lock_xp ); |
---|
88 | |
---|
89 | /*************************************************************************************** |
---|
90 | * This function releases a remote rwlock for a writer. |
---|
91 | * It decrements the calling thread locks count when the lock has been released. |
---|
92 | *************************************************************************************** |
---|
93 | * @ lock_xp : extended pointer on the remote rwlock |
---|
94 | **************************************************************************************/ |
---|
95 | void remote_rwlock_wr_unlock( xptr_t lock_xp ); |
---|
96 | |
---|
97 | /*************************************************************************************** |
---|
98 | * Display the lock state on kernel TTY. |
---|
99 | *************************************************************************************** |
---|
100 | * @ lock_xp : extended pointer on the remote rwlock |
---|
101 | * @ comment : comment to be printed. |
---|
102 | **************************************************************************************/ |
---|
103 | void remote_rwlock_print( xptr_t lock_xp, |
---|
104 | char * comment ); |
---|
105 | |
---|
106 | #endif |
---|