Changeset 563 for trunk/kernel/libk/remote_mutex.h
- Timestamp:
- Oct 4, 2018, 11:16:13 PM (6 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/kernel/libk/remote_mutex.h
r457 r563 1 1 /* 2 * remote_mutex.h - remote_mutex operationsdefinition.2 * remote_mutex.h - POSIX mutex definition. 3 3 * 4 * Authors Alain Greiner (2016 )4 * Authors Alain Greiner (2016,2017,2018) 5 5 * 6 6 * Copyright (c) UPMC Sorbonne Universites … … 30 30 31 31 /*************************************************************************************** 32 * This file defines a POSIX compliant mutex.32 * This file defines an user level POSIX compliant mutex. 33 33 * 34 * It is used by muti-threaded applications to synchronise threads running in 35 * different clusters, as all access functions uses hal_remote_lw() / hal_remote_sw() 36 * portable remote access primitives. 34 * It can be used by muti-threaded user applications to synchronise user threads 35 * running in different clusters. 37 36 * 38 37 * A mutex is declared by a given user process as a "pthread_mutex_t" global variable. … … 41 40 * For each user mutex, ALMOS-MKH creates a kernel "remote_mutex_t" structure, 42 41 * dynamically allocated in the reference cluster by the remote_mutex_create() function, 43 * and destroyed by the remote_ barrier_destroy() function, using RPC if the calling thread42 * and destroyed by the remote_mutex_destroy() function, using RPC if the calling thread 44 43 * is not running in the reference cluster. 45 44 * … … 53 52 54 53 /***************************************************************************************** 55 * This structure defines the mutex descriptor. 56 * - It contains an xlist of all mutex dynamically created by a given process, 57 * rooted in the reference process descriptor. 58 * - It contains the root of another xlist to register all waiting threads. 54 * This structure defines the kernel implementation of an user level mutex. 59 55 ****************************************************************************************/ 60 56 61 57 typedef struct remote_mutex_s 62 58 { 63 remote_ spinlock_t lock; /*! lock protecting list of waiting threads*/59 remote_busylock_t lock; /*! lock protecting the mutex state */ 64 60 intptr_t ident; /*! mutex identifier (vaddr in user space) */ 65 uint32_t value; /*! mutex non allocated if 0 */ 66 xptr_t owner; /*! extended pointer on owner thread */ 61 uint32_t taken; /*! mutex non allocated if 0 */ 67 62 xlist_entry_t list; /*! member of list of mutex in same process */ 68 63 xlist_entry_t root; /*! root of list of waiting threads */ 64 xptr_t owner; /*! extended pointer on owner thread */ 69 65 } 70 66 remote_mutex_t; … … 81 77 82 78 /*************************************************************************************** 83 * This function implement the pthread_mutex_init() syscall.79 * This function implements the pthread_mutex_init() syscall. 84 80 * It allocates memory for the mutex descriptor in the reference cluster for 85 81 * the calling process, it initializes the mutex state, and register it in the … … 87 83 *************************************************************************************** 88 84 * @ ident : mutex identifier (virtual address in user space). 89 * @ return 0 if success / return ENOMEM if failure.85 * @ return 0 if success / ENOMEM if no memory / EINVAL if invalid argument. 90 86 **************************************************************************************/ 91 87 error_t remote_mutex_create( intptr_t ident ); 92 88 93 89 /*************************************************************************************** 94 * This function implement the pthread_mutex_destroy() syscall.90 * This function implements the pthread_mutex_destroy() syscall. 95 91 * It releases thr memory allocated for the mutex descriptor, and remove the mutex 96 92 * from the list of mutex owned by the reference process. … … 101 97 102 98 /*************************************************************************************** 103 * This blocking function get ownership of a remote mutex. 99 * This blocking function implements the pthread_mutex_lock() syscall. 100 * It returns only when the ownership of the mutex identified by the <mutex_xp> 101 * argument has been obtained by the calling thread. It register in the mutex waiting 102 * queue when the mutex is already taken by another thread. 104 103 *************************************************************************************** 105 104 * @ mutex_xp : extended pointer on mutex descriptor. … … 108 107 109 108 /*************************************************************************************** 110 * This function releases a remote mutex. 109 * This function implements the pthread_mutex_unlock() syscall. 110 * It cheks that the calling thread is actually the mutex owner. 111 * It reset the "taken" & "owner" fields for the mutex identified by <mutex_xp>. 112 * It unblocks the first thread registered in the mutex waiting queue, when the 113 * queue is not empty. 111 114 *************************************************************************************** 112 115 * @ mutex_xp : extended pointer on mutex descriptor. 116 * @ return 0 if success / return non zero if calling thread is not mutex owner. 113 117 **************************************************************************************/ 114 void remote_mutex_unlock( xptr_t mutex_xp ); 118 error_t remote_mutex_unlock( xptr_t mutex_xp ); 119 120 /*************************************************************************************** 121 * This non blocking function function attempts to lock a mutex without blocking. 122 *************************************************************************************** 123 * @ mutex_xp : extended pointer on mutex descriptor. 124 * @ return 0 if success / return non zero if already taken. 125 **************************************************************************************/ 126 error_t remote_mutex_trylock( xptr_t mutex_xp ); 115 127 116 128
Note: See TracChangeset
for help on using the changeset viewer.