source: trunk/kernel/libk/remote_sem.h @ 582

Last change on this file since 582 was 581, checked in by alain, 6 years ago

1) Improve the busylock debug infrastructure.
2) introduce a non-distributed, but portable implementation for the pthread_barrier.

File size: 6.9 KB
RevLine 
[1]1/*
[563]2 * remote_sem.h - POSIX unnamed semaphore definition.
[1]3 *
[563]4 * Author   Alain Greiner (2016,2017,2018)
[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
[563]12e* the Free Software Foundation; version 2.0 of the License.
[1]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 _SEMAPHORE_H_
25#define _SEMAPHORE_H_
26
[457]27#include <hal_kernel_types.h>
[1]28#include <xlist.h>
[563]29#include <remote_busylock.h>
[1]30
[563]31/********************************************************************************************n
32 * This is the kernel representation of an user level, POSIX compliant unnamed semaphore.
[1]33 *
[563]34 * It can be used by muti-threaded user applications to synchronise user threads
35 * running in different clusters.
36 *
37* A semaphore is declared by a given user process as a "sem_t" global variable.
[1]38 * The user "sem_t" structure is implemented as an unsigned long, but the value is not
39 * used by the kernel. ALMOS-MKH uses only the sem_t virtual address as an identifier.
[563]40 * For each user semaphore, ALMOS-MKH creates a kernel "remote_sem_t" structure,
41 * dynamically allocated in the reference cluster by the remote_sem_create() function,
42 * and destroyed by the remote_sem_destroy() function, using RPC if the calling thread is not
43 * running in the reference cluster.
44 *
45 * The threads accessing the semaphore with the sem_get_value(), sem_wait(), sem_post()
46 * syscalls can be running in any cluster, as these syscalls access the "remote_sem_t"
47 * structure with remote_read / remote_write access functions.
[1]48 ********************************************************************************************/
49
50
51/*********************************************************************************************
[563]52 * This structure defines the kernel implementation of an user level semaphore.
[1]53 ********************************************************************************************/
54
55typedef struct remote_sem_s
56{
[563]57        remote_busylock_t lock;          /*! lock protecting the semaphore state                */
[1]58        uint32_t          count;         /*! current value                                      */
59    intptr_t          ident;         /*! virtual address in user space == identifier        */
[23]60    xlist_entry_t     root;          /*! root of waiting thread queue                       */
61    xlist_entry_t     list;          /*! member of list of semaphores in same process       */
[1]62}
63remote_sem_t;
64
65
66/*********************************************************************************************
67 * This function returns an extended pointer on the remote semaphore identified
[23]68 * by its virtual address in a given user process. It makes an associative search,
[563]69 * scanning the list of user semaphores rooted in the reference process descriptor.
[1]70 *********************************************************************************************
71 * @ process  : pointer on local process descriptor.
[563]72 * @ ident    : semaphore virtual address, used as identifier.
[1]73 * @ returns extended pointer on semaphore if success / returns XPTR_NULL if not found.
74 ********************************************************************************************/
[563]75xptr_t remote_sem_from_ident( intptr_t  ident );
[1]76
77/*********************************************************************************************
78 * This function implements the SEM_INIT operation.
79 * It allocates memory for a remote semaphore in reference cluster, using a RPC if required,
[457]80 * and initializes it, using remote accesses from values defined by the <vaddr> and <value>
[563]81 * arguments. It register this semaphore in the calling process list of user semaphores.
[1]82 *********************************************************************************************
[457]83 * @ vaddr     : [in] semaphore virtual address, used as identifier.
84 * @ value     : [in] semaphore initial value.
85 * @ returns 0 if success / returns -1 if no memory.
[1]86 ********************************************************************************************/
[23]87error_t remote_sem_create( intptr_t  vaddr,
[563]88                           uint32_t  value );
[1]89 
90/****************************yy***************************************************************
[23]91 * This function implements the SEM_DESTROY operation.
92 * It desactivates the semaphore, and releases the physical memory allocated in the
93 * reference cluster, using a RPC if required.
94 *********************************************************************************************
[457]95 * @ sem_xp   : [in] extended pointer on semaphore.
[23]96 ********************************************************************************************/
97void remote_sem_destroy( xptr_t sem_xp );
98
99/****************************yy***************************************************************
[1]100 * This blocking function implements the SEM_WAIT operation.
[563]101 * - It returns only when the remote semaphore has a non-zero value, and has been
102 *   atomically decremented.
103 * - If the semaphore has a zero value, it register the calling thread in the semaphore
104 *   waiting queue, block the thread, and yield.
[1]105 *********************************************************************************************
[457]106 * @ sem_xp   : [in] extended pointer on semaphore.
[1]107 ********************************************************************************************/
108void remote_sem_wait( xptr_t sem_xp );
109
110/****************************yy***************************************************************
[581]111 * This function implements the SEM_POST operation.
[563]112 * - It atomically increments the remote semaphore.
113 * - If the waiting queue is not empty, it wakes up all waiting thread.
[1]114 *********************************************************************************************
[457]115 * @ sem_xp   : [in] extended pointer on semaphore.
[1]116 ********************************************************************************************/
117void remote_sem_post( xptr_t sem_xp );
118
119/****************************yy***************************************************************
120 * This function implements the SEM_GETVALUE operation.
121 * It returns in the <data> buffer the semaphore current value.
122 *********************************************************************************************
[457]123 * @ sem_xp   : [in]  extended pointer on semaphore.
124 * @ data     : [out] local pointer on buffer for returned value.
[1]125 ********************************************************************************************/
126void remote_sem_get_value( xptr_t      sem_xp,
127                           uint32_t  * data );
128
129
130#endif  /* _SEMAPHORE_H_ */
Note: See TracBrowser for help on using the repository browser.