Ignore:
Timestamp:
Oct 4, 2018, 11:16:13 PM (6 years ago)
Author:
alain
Message:

Complete restructuration of kernel spinlocks.

File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/kernel/libk/remote_condvar.h

    r457 r563  
    11/*
    2  * remote_condvar.h - distributed kernel condvar definition
     2 * remote_condvar.h: POSIX condition variable definition.     
    33 *
    4  * Author  Alain Greiner (2016,2017)
     4 * Authors  Alain Greiner (2016,2017,2018)
    55 *
    66 * Copyright (c) UPMC Sorbonne Universites
     
    1818 *
    1919 * 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,
    2121 * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
    2222 */
    2323
    24 #ifndef _REMOTE_CONDVAR_H_
    25 #define _REMOTE_CONDVAR_H_
     24#ifndef _CONDVAR_H_
     25#define _CONDVAR_H_
    2626
    2727#include <kernel_config.h>
    2828#include <hal_kernel_types.h>
    29 #include <remote_spinlock.h>
     29#include <remote_busylock.h>
    3030#include <xlist.h>
    3131
    32 /*****************************************************************************************
    33  *          This file defines a POSIX compliant condvar.
     32/*******************************************************************************************
     33 *     This file define an user level POSIX compliant condition variable.
    3434 *
    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.
    3837 *
    3938 * A condvar is declared by a given user process as a "pthread_cond_t" global variable.
    4039 * 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.
     40 * kernel. ALMOS-MKH uses only the mutex virtual address as an identifier.
    4241 * For each user condvar, ALMOS-MKH creates a kernel "remote_condvar_t" structure,
    4342 * 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 ******************************************************************************************/
    4853
    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 ******************************************************************************************/
    5657
    5758typedef struct remote_condvar_s
    5859{
    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        */
    6364}
    6465remote_condvar_t;
    6566
    66 /*****************************************************************************************
     67/*********************************************************************************************
    6768 * This function returns an extended pointer on the remote condvar identified
    6869 * 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  ****************************************************************************************/
     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 ********************************************************************************************/
    7475xptr_t remote_condvar_from_ident( intptr_t  ident );
    7576
    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 ******************************************************************************************/
     85error_t remote_condvar_create( intptr_t   vaddr );
    8686
    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 );
     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 ******************************************************************************************/
     94void remote_condvar_destroy( xptr_t condvar_xp );
    9595
    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 ******************************************************************************************/
     107void remote_condvar_wait( xptr_t condvar_xp,
     108                          xptr_t mutex_xp );
    108109
    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 ******************************************************************************************/
     119void remote_condvar_signal( xptr_t condvar_xp );
    116120
    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 ******************************************************************************************/
     130void remote_condvar_broadcast( xptr_t condvar_xp );
    124131
    125 
    126 #endif  /* _REMOTE_BARRIER_H_ */
     132#endif  /* _CONDVAR_H_ */
Note: See TracChangeset for help on using the changeset viewer.