Changeset 563 for trunk/kernel/libk/remote_condvar.h
- Timestamp:
- Oct 4, 2018, 11:16:13 PM (6 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/kernel/libk/remote_condvar.h
r457 r563 1 1 /* 2 * remote_condvar.h - distributed kernel condvar definition2 * remote_condvar.h: POSIX condition variable definition. 3 3 * 4 * Author Alain Greiner (2016,2017)4 * Authors Alain Greiner (2016,2017,2018) 5 5 * 6 6 * Copyright (c) UPMC Sorbonne Universites … … 18 18 * 19 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,20 * along with ALMOS-kernel; if not, write to the Free Software Foundation, 21 21 * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA 22 22 */ 23 23 24 #ifndef _ REMOTE_CONDVAR_H_25 #define _ REMOTE_CONDVAR_H_24 #ifndef _CONDVAR_H_ 25 #define _CONDVAR_H_ 26 26 27 27 #include <kernel_config.h> 28 28 #include <hal_kernel_types.h> 29 #include <remote_ spinlock.h>29 #include <remote_busylock.h> 30 30 #include <xlist.h> 31 31 32 /***************************************************************************************** 33 * This file defines a POSIX compliant condvar.32 /******************************************************************************************* 33 * This file define an user level POSIX compliant condition variable. 34 34 * 35 * It is used by multi-threaded applications to synchronise threads running in 36 * different clusters, as all access functions uses hal_remote_lw() / hal_remote_sw() 37 * portable remote access primitives. 35 * It can be used by muti-threaded user applications to synchronise user threads 36 * running in different clusters. 38 37 * 39 38 * A condvar is declared by a given user process as a "pthread_cond_t" global variable. 40 39 * This user type is implemented as an unsigned long, but the value is not used by the 41 * kernel. ALMOS-MKH uses only the condvarvirtual address as an identifier.40 * kernel. ALMOS-MKH uses only the mutex virtual address as an identifier. 42 41 * For each user condvar, ALMOS-MKH creates a kernel "remote_condvar_t" structure, 43 42 * dynamically allocated in the reference cluster by the remote_condvar_create() function, 44 * and destroyed by the remote_condvar_destroy() function, using RPC if the calling 45 * thread is not running in the reference cluster. The synchronisation is done by the 46 * remote_condvar_wait(), remote_condvar_signal(), remote_convar_broadcast() functions. 47 ****************************************************************************************/ 43 * and destroyed by the remote_condvar_destroy() function, using RPC if the calling thread 44 * is not running in the reference cluster. 45 * 46 * The blocking "remote_condvar_wait() function allowx the calling thread to efficiently 47 * wait for a change in a shared user object. The calling thread blocks and register in 48 * a waiting queue attached to the condvar. The blocked thread is unblocked by another 49 * thread calling the remote_convar signal() or remote_condvar_broadcast(). 50 * The three associated methods wait(), signal() and broadcast() must be called 51 * by a thread holding the mutex associated to the condvar. 52 ******************************************************************************************/ 48 53 49 /***************************************************************************************** 50 * This structure defines the condvar descriptor. 51 * - It contains an xlist of all condvars dynamically created by a given process, 52 * rooted in the reference process descriptor. 53 * - It contains also the root of another xlist of all threads waiting on the condvar, 54 * resumed by a remote_condvar_signal(), or remote_condvar_broadcast(). 55 ****************************************************************************************/ 54 /******************************************************************************************* 55 * This structure defines the kernel implementation of a condvar. 56 ******************************************************************************************/ 56 57 57 58 typedef struct remote_condvar_s 58 59 { 59 remote_ spinlock_t lock; /*! lock protecting the waiting threads list*/60 intptr_t ident; /*! virtual address in user space == identifier*/61 xlist_entry_t list; /*! member of list of condvars in same process*/62 xlist_entry_t root; /*! root of list of waiting threads*/60 remote_busylock_t lock; /*! lock protecting the condvar state */ 61 intptr_t ident; /*! virtual address in user space == identifier */ 62 xlist_entry_t root; /*! root of waiting threads queue */ 63 xlist_entry_t list; /*! member of list of condvars in same process */ 63 64 } 64 65 remote_condvar_t; 65 66 66 /***************************************************************************************** 67 /********************************************************************************************* 67 68 * This function returns an extended pointer on the remote condvar identified 68 69 * by its virtual address in a given user process. It makes an associative search, 69 * scanning the list of condvars rooted in the reference process descriptor.70 ***************************************************************************************** 71 * @ ident : condvarvirtual address, used as identifier.72 * @ returns extended pointer on condvarif success / returns XPTR_NULL if not found.73 **************************************************************************************** /70 * scanning the list of user condvars rooted in the reference process descriptor. 71 ********************************************************************************************* 72 * @ ident : semaphore virtual address, used as identifier. 73 * @ returns extended pointer on semaphore if success / returns XPTR_NULL if not found. 74 ********************************************************************************************/ 74 75 xptr_t remote_condvar_from_ident( intptr_t ident ); 75 76 76 /***************************************************************************************** 77 * This function implement the pthread_condvar_init() syscall. 78 * It allocates memory for the condvar descriptor in the reference cluster for 79 * the calling process, it initializes the condvar state, and register it in the 80 * list of condvars owned by the reference process. 81 ***************************************************************************************** 82 * @ ident : condvar identifier (virtual address in user space). 83 * @ return 0 if success / return ENOMEM if failure. 84 ****************************************************************************************/ 85 error_t remote_condvar_create( intptr_t ident ); 77 /******************************************************************************************* 78 * This function implements the CONVAR_INIT operation. 79 * This function creates and initializes a remote_condvar, identified by its virtual 80 * address <vaddr> in the client process reference cluster, using RPC if required. 81 * It registers this user condvar in the reference process descriptor. 82 ******************************************************************************************* 83 * @ vaddr : [in] condvar virtual addresss, used as identifier. 84 ******************************************************************************************/ 85 error_t remote_condvar_create( intptr_t vaddr ); 86 86 87 /***************************************************************************************** 88 * This function implement the pthread_condvar_destroy() syscall.89 * It releases the memory allocated for the condvar descriptor, and remove the condvar90 * from the list of condvars owned by the reference process.91 ***************************************************************************************** 92 * @ condvar_xp : extended pointer on condvar descriptor.93 **************************************************************************************** /94 void remote_condvar_destroy( xptr_t 87 /******************************************************************************************* 88 * This function implements the CONVAR_DESTROY operation. 89 * This function creates and initializes a remote_condvar, identified by its virtual 90 * address in the client process reference cluster, and registers it in process descriptor. 91 ******************************************************************************************* 92 * @ condvar_xp : [in] extended pointer on buffer to store xptr on created condvar. 93 ******************************************************************************************/ 94 void remote_condvar_destroy( xptr_t condvar_xp ); 95 95 96 /***************************************************************************************** 97 * This function implement the pthread_condvar_wait() syscall. 98 * It unlock the mutex. 99 * It register the calling thread in the condvar waiting queue, block the calling thread 100 * on the THREAD_BLOCKED_CONDVAR condition and deschedule. 101 * it lock the mutex. 102 ***************************************************************************************** 103 * @ condvar_xp : extended pointer on condvar descriptor. 104 * @ mutex_xp : extended pointer on associated mutex descriptor. 105 ****************************************************************************************/ 106 void remote_condvar_wait( xptr_t condvar_xp, 107 xptr_t mutex_xp ); 96 /******************************************************************************************* 97 * This function implements the CONDVAR_WAIT operation. 98 * It atomically releases the mutex identified by the <mutex_xp> argument, 99 * registers the calling thread in the condvar waiting queue identified by the 100 * <condvar_xp> argument, blocks and deschedules this calling thread. 101 * Later, when the calling thread resume, this function re-acquire the mutex and returns. 102 * WARNING: the calling thread must hold the mutex associated to the condvar. 103 ******************************************************************************************* 104 * @ condvar_xp : [in] extended pointer on condvar. 105 * @ mutex_xp : [in] extended pointer on mutex. 106 ******************************************************************************************/ 107 void remote_condvar_wait( xptr_t condvar_xp, 108 xptr_t mutex_xp ); 108 109 109 /***************************************************************************************** 110 * This function implement the pthread_condvar_signal() syscall. 111 * It unblocks the first waiting thread in the condvar waiting queue. 112 ***************************************************************************************** 113 * @ condvar_xp : extended pointer on condvar descriptor. 114 ****************************************************************************************/ 115 void remote_condvar_signal( xptr_t condvar_xp ); 110 /******************************************************************************************* 111 * This function implements the CONDVAR_SIGNAL operation. 112 * It remove one waiting thread from a remote_condvar waiting queue identified by the 113 * <condvar_xp> argument and unblocks this thread. 114 * It does nothing if the queue is empty. 115 * WARNING: the calling thread must hold the mutex associated to the condvar. 116 ******************************************************************************************* 117 * @ condvar_xp : extended pointer on remote_condvar. 118 ******************************************************************************************/ 119 void remote_condvar_signal( xptr_t condvar_xp ); 116 120 117 /***************************************************************************************** 118 * This function implement the pthread_condvar_broadcast() syscall. 119 * It unblocks all waiting threads in the condvar waiting queue. 120 ***************************************************************************************** 121 * @ condvar_xp : extended pointer on condvar descriptor. 122 ****************************************************************************************/ 123 void remote_condvar_broadcast( xptr_t condvar_xp ); 121 /******************************************************************************************* 122 * This function implements the CONDVAR_BROADCAST operation. 123 * It removes all threads from a remote_condvar waiting queue identified by the 124 * <condvar_xp> argument, and unblocks all these threads. 125 * It does nothing if the queue is empty. 126 * WARNING: the calling thread must hold the mutex associated to the condvar. 127 ******************************************************************************************* 128 * @ condvar_xp : extended pointer on remote_condvar. 129 ******************************************************************************************/ 130 void remote_condvar_broadcast( xptr_t condvar_xp ); 124 131 125 126 #endif /* _REMOTE_BARRIER_H_ */ 132 #endif /* _CONDVAR_H_ */
Note: See TracChangeset
for help on using the changeset viewer.