source: trunk/kernel/libk/remote_rwlock.h @ 304

Last change on this file since 304 was 50, checked in by alain, 7 years ago

bloup

File size: 5.3 KB
RevLine 
[1]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
[14]27#include <kernel_config.h>
[1]28#include <hal_types.h>
29#include <xlist.h>
30
31/***************************************************************************************
[23]32 * This file defines a remote kernel lock, that supports several simultaneous read
[1]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 *
[23]43 * It uses a busy-waiting policy if the lock is already allocated to another thread.
[1]44 **************************************************************************************/
45
46typedef struct remote_rwlock_s
47{
48    uint32_t     ticket;                /*! first free ticket index                   */
49    uint32_t     current;               /*! ticket index of current owner             */
50    uint32_t     count;                 /*! current number of reader threads          */
51    xptr_t       owner;                 /*! extended pointer on writer thread         */
52} 
53remote_rwlock_t;
54
55/***************************************************************************************
56 * This function initializes a remote rwlock.
57 ***************************************************************************************
58 * @ lock_xp    : extended pointer on the remote rwlock
59 **************************************************************************************/
60void remote_rwlock_init( xptr_t lock_xp );
61
62/***************************************************************************************
63 * This blocking function get access to a remote rwlock for a reader.
64 * It increments the calling thread locks count when the lock has been taken.
65 ***************************************************************************************
66 * @ lock_xp    : extended pointer on the remote rwlock
67 **************************************************************************************/
68void remote_rwlock_rd_lock( xptr_t lock_xp );
69
70/***************************************************************************************
71 * This function releases a remote rwlock for a reader.
72 * It decrements the calling thread locks count when the lock has been released.
73 ***************************************************************************************
74 * @ lock_xp    : extended pointer on the remote rwlock
75 **************************************************************************************/
76void remote_rwlock_rd_unlock( xptr_t lock_xp );
77
78/***************************************************************************************
79 * This blocking function get access to a remote rwlock for a writer.
80 * It increments the calling thread locks count when the lock has been taken.
81 ***************************************************************************************
82 * @ lock_xp    : extended pointer on the remote rwlock
83 **************************************************************************************/
84void remote_rwlock_wr_lock( xptr_t lock_xp );
85
86/***************************************************************************************
87 * This function releases a remote rwlock for a writer.
88 * It decrements the calling thread locks count when the lock has been released.
89 ***************************************************************************************
90 * @ lock_xp    : extended pointer on the remote rwlock
91 **************************************************************************************/
92void remote_rwlock_wr_unlock( xptr_t lock_xp );
93
[50]94/***************************************************************************************
95 * Display the lock state on kernel TTY.
96 ***************************************************************************************
97 * @ lock_xp    : extended pointer on the remote rwlock
98 * @ comment    : comment to be printed.
99 **************************************************************************************/
100void remote_rwlock_print( xptr_t   lock_xp,
101                          char   * comment );
102
[1]103#endif
Note: See TracBrowser for help on using the repository browser.