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

Complete restructuration of kernel spinlocks.

File:
1 edited

Legend:

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

    r457 r563  
    11/*
    2  * remote_mutex.h -  remote_mutex operations definition.
     2 * remote_mutex.h -  POSIX mutex definition.
    33 *
    4  * Authors   Alain Greiner   (2016)
     4 * Authors   Alain Greiner   (2016,2017,2018)
    55 *
    66 * Copyright (c) UPMC Sorbonne Universites
     
    3030
    3131/***************************************************************************************
    32  *    This file defines a POSIX compliant mutex.
     32 *    This file defines an user level POSIX compliant mutex.
    3333 *
    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.
    3736 *
    3837 * A mutex is declared by a given user process as a "pthread_mutex_t" global variable.
     
    4140 * For each user mutex, ALMOS-MKH creates a kernel "remote_mutex_t" structure,
    4241 * 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 thread
     42 * and destroyed by the remote_mutex_destroy() function, using RPC if the calling thread
    4443 * is not running in the reference cluster.
    4544 *
     
    5352
    5453/*****************************************************************************************
    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.
    5955 ****************************************************************************************/
    6056
    6157typedef struct remote_mutex_s
    6258{
    63     remote_spinlock_t  lock;            /*! lock protecting list of waiting threads   */
     59    remote_busylock_t  lock;            /*! lock protecting the mutex state           */
    6460    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                  */
    6762    xlist_entry_t      list;            /*! member of list of mutex in same process   */
    6863    xlist_entry_t      root;            /*! root of list of waiting threads           */
     64    xptr_t             owner;           /*! extended pointer on owner thread          */
    6965}
    7066remote_mutex_t;
     
    8177
    8278/***************************************************************************************
    83  * This function implement the pthread_mutex_init() syscall.
     79 * This function implements the pthread_mutex_init() syscall.
    8480 * It allocates memory for the mutex descriptor in the reference cluster for
    8581 * the calling process, it initializes the mutex state, and register it in the
     
    8783 ***************************************************************************************
    8884 * @ 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.
    9086 **************************************************************************************/
    9187error_t remote_mutex_create( intptr_t ident );
    9288
    9389/***************************************************************************************
    94  * This function implement the pthread_mutex_destroy() syscall.
     90 * This function implements the pthread_mutex_destroy() syscall.
    9591 * It releases thr memory allocated for the mutex descriptor, and remove the mutex
    9692 * from the list of mutex owned by the reference process.
     
    10197
    10298/***************************************************************************************
    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.
    104103 ***************************************************************************************
    105104 * @ mutex_xp  : extended pointer on mutex descriptor.
     
    108107
    109108/***************************************************************************************
    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.
    111114 ***************************************************************************************
    112115 * @ mutex_xp  : extended pointer on mutex descriptor.
     116 * @ return 0 if success / return non zero if calling thread is not mutex owner.
    113117 **************************************************************************************/
    114 void remote_mutex_unlock( xptr_t  mutex_xp );
     118error_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 **************************************************************************************/
     126error_t remote_mutex_trylock( xptr_t  mutex_xp );
    115127
    116128
Note: See TracChangeset for help on using the changeset viewer.