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

Last change on this file since 662 was 657, checked in by alain, 5 years ago

Introduce remote_buf.c/.h & socket.c/.h files.
Update dev_nic.c/.h files.

File size: 5.5 KB
RevLine 
[1]1/*
[657]2 * remote_rwlock.h - kernel remote read/write lock definition.
[1]3 *
[657]4 * Authors   Alain Greiner   (2016,2017,2018,2020)
[1]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>
[457]28#include <hal_kernel_types.h>
[563]29#include <remote_busylock.h>
[1]30#include <xlist.h>
31
[563]32/*******************************************************************************************
33 * This structure defines a kernel, global, read/write lock, supporting several simultaneous
34 * read accesses, but only one write access to a globally shared object, that can be
35 * accessed by threads running in any cluster.
36 * Both readers and writers take the associated busylock before accessing or updating
37 * the rwlock state, and releases the busylock after rwlock state update.
38 * - when a reader try to access the object, it increments the readers "count" when the
39 *   lock is not "taken" by a writer. It registers in the "rd_root" waiting queue, blocks,
40 *   and deschedules when the lock is taken.
41 * - when a writer try to take the rwlock, it check the "taken" field. If the lock is already
42 *   taken, or if the number of readers is non zero, it registers in the "wr_root" waiting
43 *   queue, blocks, and deschedules. It set "taken" otherwise.
[629]44 * - when a reader completes its access, it decrement the readers "count", unblock
[563]45 *   the first waiting writer if there is no other readers, and unblock all waiting
46 *   readers if there no write request.
47 * - when a  writer completes its access, it reset the "taken" field, releases the first
48 *   waiting writer if queue non empty, or releases all waiting readers if no writer.
49 ******************************************************************************************/
[1]50
[563]51
52/*******************************************************************************************
53 * This structure defines a remote rwlock.
54 ******************************************************************************************/
55
[1]56typedef struct remote_rwlock_s
57{
[563]58    remote_busylock_t   lock;        /*! busylock protecting the rwlock state             */
59        volatile uint32_t   taken;       /*! lock taken by an exclusive writer if non zero    */
60    volatile uint32_t   count;       /*! current number of simultaneous readers threads   */
61    xlist_entry_t       rd_xroot;    /*! root of list of waiting readers                  */
62    xlist_entry_t       wr_xroot;    /*! root of list of waiting writers                  */
63}
64remote_rwlock_t;
[409]65
66
[1]67/***************************************************************************************
68 * This function initializes a remote rwlock.
[563]69 * The <type> argument defines the lock usage and is only used for debug.
70 * This type is actually stored in the associated busylock descriptor.
[1]71 ***************************************************************************************
72 * @ lock_xp    : extended pointer on the remote rwlock
[563]73 * @ type       : lock usage for debug.
[1]74 **************************************************************************************/
[563]75void remote_rwlock_init( xptr_t   lock_xp,
76                         uint32_t type );
[1]77
78/***************************************************************************************
79 * This blocking function get access to a remote rwlock for a reader.
80 ***************************************************************************************
81 * @ lock_xp    : extended pointer on the remote rwlock
82 **************************************************************************************/
[563]83void remote_rwlock_rd_acquire( xptr_t lock_xp );
[1]84
85/***************************************************************************************
86 * This function releases a remote rwlock for a reader.
87 ***************************************************************************************
88 * @ lock_xp    : extended pointer on the remote rwlock
89 **************************************************************************************/
[563]90void remote_rwlock_rd_release( xptr_t lock_xp );
[1]91
92/***************************************************************************************
93 * This blocking function get access to a remote rwlock for a writer.
94 ***************************************************************************************
95 * @ lock_xp    : extended pointer on the remote rwlock
96 **************************************************************************************/
[563]97void remote_rwlock_wr_acquire( xptr_t lock_xp );
[1]98
99/***************************************************************************************
100 * This function releases a remote rwlock for a writer.
101 ***************************************************************************************
102 * @ lock_xp    : extended pointer on the remote rwlock
103 **************************************************************************************/
[563]104void remote_rwlock_wr_release( xptr_t lock_xp );
[1]105
106#endif
Note: See TracBrowser for help on using the repository browser.