[23] | 1 | /* |
---|
| 2 | * remote_condvar.h - distributed kernel condvar definition |
---|
| 3 | * |
---|
| 4 | * Author Alain Greiner (2016,2017) |
---|
| 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_CONDVAR_H_ |
---|
| 25 | #define _REMOTE_CONDVAR_H_ |
---|
| 26 | |
---|
| 27 | #include <kernel_config.h> |
---|
[457] | 28 | #include <hal_kernel_types.h> |
---|
[23] | 29 | #include <remote_spinlock.h> |
---|
| 30 | #include <xlist.h> |
---|
| 31 | |
---|
| 32 | /***************************************************************************************** |
---|
| 33 | * This file defines a POSIX compliant condvar. |
---|
| 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. |
---|
| 38 | * |
---|
| 39 | * A condvar is declared by a given user process as a "pthread_cond_t" global variable. |
---|
| 40 | * This user type is implemented as an unsigned long, but the value is not used by the |
---|
| 41 | * kernel. ALMOS-MKH uses only the condvar virtual address as an identifier. |
---|
| 42 | * For each user condvar, ALMOS-MKH creates a kernel "remote_condvar_t" structure, |
---|
| 43 | * 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 | ****************************************************************************************/ |
---|
| 48 | |
---|
| 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 | ****************************************************************************************/ |
---|
| 56 | |
---|
| 57 | typedef struct remote_condvar_s |
---|
| 58 | { |
---|
| 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 */ |
---|
| 63 | } |
---|
| 64 | remote_condvar_t; |
---|
| 65 | |
---|
| 66 | /***************************************************************************************** |
---|
| 67 | * This function returns an extended pointer on the remote condvar identified |
---|
| 68 | * 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 : condvar virtual address, used as identifier. |
---|
| 72 | * @ returns extended pointer on condvar if success / returns XPTR_NULL if not found. |
---|
| 73 | ****************************************************************************************/ |
---|
| 74 | xptr_t remote_condvar_from_ident( intptr_t ident ); |
---|
| 75 | |
---|
| 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 ); |
---|
| 86 | |
---|
| 87 | /***************************************************************************************** |
---|
| 88 | * This function implement the pthread_condvar_destroy() syscall. |
---|
| 89 | * It releases the memory allocated for the condvar descriptor, and remove the condvar |
---|
| 90 | * 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 condvar_xp ); |
---|
| 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 ); |
---|
| 108 | |
---|
| 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 ); |
---|
| 116 | |
---|
| 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 ); |
---|
| 124 | |
---|
| 125 | |
---|
| 126 | #endif /* _REMOTE_BARRIER_H_ */ |
---|