source: trunk/kernel/libk/remote_mutex.h @ 442

Last change on this file since 442 was 23, checked in by alain, 8 years ago

Introduce syscalls.

File size: 6.1 KB
RevLine 
[23]1/*
2 * remote_mutex.h -  remote_mutex operations definition.
3 *
4 * Authors   Alain Greiner   (2016)
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_MUTEX_H_
25#define _REMOTE_MUTEX_H_
26
27#include <kernel_config.h>
28#include <hal_types.h>
29#include <xlist.h>
30
31/***************************************************************************************
32 *    This file defines a POSIX compliant mutex.
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.
37 *
38 * A mutex is declared by a given user process as a "pthread_mutex_t" global variable.
39 * This user type is implemented as an unsigned long, but the value is not used by the
40 * kernel. ALMOS-MKH uses only the mutex virtual address as an identifier.
41 * For each user mutex, ALMOS-MKH creates a kernel "remote_mutex_t" structure,
42 * 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
44 * is not running in the reference cluster.
45 *
46 * The blocking "remote_mutex_lock()" function implements a descheduling policy when
47 * the lock is already taken by another thread : the calling thread is registered
48 * in a waiting queue, rooted in the mutex structure, and the the calling thread
49 * is blocked on the THREAD_BLOCKED_MUTEX condition.
50 * The "remote_mutex_unlock()" function unblocks the first waiting thread in the queue
51 * without releasing the mutex if queue is not empty.
52 **************************************************************************************/
53
54/*****************************************************************************************
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.
59 ****************************************************************************************/
60
61typedef struct remote_mutex_s
62{
63    remote_spinlock_t  lock;            /*! lock protecting list of waiting threads   */
64    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          */
67    xlist_entry_t      list;            /*! member of list of mutex in same process   */
68    xlist_entry_t      root;            /*! root of list of waiting threads           */
69}
70remote_mutex_t;
71
72/***************************************************************************************
73 * This function returns an extended pointer on the remote mutex, identified
74 * by its virtual address in a given user process. It makes an associative search,
75 * scanning the list of mutex rooted in the reference process descriptor.
76 ***************************************************************************************
77 * @ ident    : mutex virtual address, used as identifier.
78 * @ returns extended pointer on mutex if success / returns XPTR_NULL if not found.
79 **************************************************************************************/
80xptr_t remote_mutex_from_ident( intptr_t  ident );
81
82/***************************************************************************************
83 * This function implement the pthread_mutex_init() syscall.
84 * It allocates memory for the mutex descriptor in the reference cluster for
85 * the calling process, it initializes the mutex state, and register it in the
86 * list of mutex owned by the reference process.
87 ***************************************************************************************
88 * @ ident       : mutex identifier (virtual address in user space).
89 * @ return 0 if success / return ENOMEM if failure.
90 **************************************************************************************/
91error_t remote_mutex_create( intptr_t ident );
92
93/***************************************************************************************
94 * This function implement the pthread_mutex_destroy() syscall.
95 * It releases thr memory allocated for the mutex descriptor, and remove the mutex
96 * from the list of mutex owned by the reference process.
97 ***************************************************************************************
98 * @ mutex_xp  : extended pointer on mutex descriptor.
99 **************************************************************************************/
100void remote_mutex_destroy( xptr_t  mutex_xp );
101
102/***************************************************************************************
103 * This blocking function get ownership of a remote mutex.
104 ***************************************************************************************
105 * @ mutex_xp  : extended pointer on mutex descriptor.
106 **************************************************************************************/
107void remote_mutex_lock( xptr_t  mutex_xp );
108
109/***************************************************************************************
110 * This function releases a remote mutex.
111 ***************************************************************************************
112 * @ mutex_xp  : extended pointer on mutex descriptor.
113 **************************************************************************************/
114void remote_mutex_unlock( xptr_t  mutex_xp );
115
116
117
118#endif
Note: See TracBrowser for help on using the repository browser.