Changeset 563 for trunk/kernel/libk/remote_sem.h
- Timestamp:
- Oct 4, 2018, 11:16:13 PM (6 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/kernel/libk/remote_sem.h
r457 r563 1 1 /* 2 * remote_sem.h - POSIX unnam med semaphore definition.2 * remote_sem.h - POSIX unnamed semaphore definition. 3 3 * 4 * Author Alain Greiner (2016)4 * Author Alain Greiner (2016,2017,2018) 5 5 * 6 6 * Copyright (c) UPMC Sorbonne Universites … … 10 10 * ALMOS-MKH is free software; you can redistribute it and/or modify it 11 11 * under the terms of the GNU General Public License as published by 12 12 e* the Free Software Foundation; version 2.0 of the License. 13 13 * 14 14 * ALMOS-MKH is distributed in the hope that it will be useful, but … … 27 27 #include <hal_kernel_types.h> 28 28 #include <xlist.h> 29 #include <remote_ spinlock.h>29 #include <remote_busylock.h> 30 30 31 /******************************************************************************************** *32 * This file defines aPOSIX compliant unnamed semaphore.31 /********************************************************************************************n 32 * This is the kernel representation of an user level, POSIX compliant unnamed semaphore. 33 33 * 34 * A semaphore is declared by a given user process as a "sem_t" global variable. 34 * It can be used by muti-threaded user applications to synchronise user threads 35 * running in different clusters. 36 * 37 * A semaphore is declared by a given user process as a "sem_t" global variable. 35 38 * The user "sem_t" structure is implemented as an unsigned long, but the value is not 36 39 * used by the kernel. ALMOS-MKH uses only the sem_t virtual address as an identifier. 37 * For each user semaphore, ALMOS-MKH creates a kernel "remote_sem_t" structure. 38 * - This structure is allocated in the reference cluster by the sem_init() syscall, 39 * and destroyed by the sem_destroy() syscall, using RPC if the calling thread is not 40 * running in the reference cluster. 41 * - The threads accessing the semaphore with the sem_get_value(), sem_wait(), sem_post() 42 * syscalls can be running in any cluster, as these syscalls access the "remote_sem_t" 43 * structure with remote_read / remote_write access functions. 40 * For each user semaphore, ALMOS-MKH creates a kernel "remote_sem_t" structure, 41 * dynamically allocated in the reference cluster by the remote_sem_create() function, 42 * and destroyed by the remote_sem_destroy() function, using RPC if the calling thread is not 43 * running in the reference cluster. 44 * 45 * The threads accessing the semaphore with the sem_get_value(), sem_wait(), sem_post() 46 * syscalls can be running in any cluster, as these syscalls access the "remote_sem_t" 47 * structure with remote_read / remote_write access functions. 44 48 ********************************************************************************************/ 45 49 46 50 47 51 /********************************************************************************************* 48 * This structure defines the kernel semaphore descriptor. 49 * - It contains the root of a waiting threads queue, implemented as a distributed xlist. 50 * - It contains an xlist of all semaphores, rooted in the reference process descriptor. 51 * - It contains a lock protecting both the semaphore value and the waiting queue. 52 * This structure defines the kernel implementation of an user level semaphore. 52 53 ********************************************************************************************/ 53 54 54 55 typedef struct remote_sem_s 55 56 { 56 remote_ spinlock_t lock; /*! lock protecting both count and wait_queue*/57 remote_busylock_t lock; /*! lock protecting the semaphore state */ 57 58 uint32_t count; /*! current value */ 58 59 intptr_t ident; /*! virtual address in user space == identifier */ … … 66 67 * This function returns an extended pointer on the remote semaphore identified 67 68 * by its virtual address in a given user process. It makes an associative search, 68 * scanning the list of semaphores rooted in the reference process descriptor.69 * scanning the list of user semaphores rooted in the reference process descriptor. 69 70 ********************************************************************************************* 70 71 * @ process : pointer on local process descriptor. 71 * @ vaddr: semaphore virtual address, used as identifier.72 * @ ident : semaphore virtual address, used as identifier. 72 73 * @ returns extended pointer on semaphore if success / returns XPTR_NULL if not found. 73 74 ********************************************************************************************/ 74 xptr_t remote_sem_from_ vaddr( intptr_t vaddr);75 xptr_t remote_sem_from_ident( intptr_t ident ); 75 76 76 77 /********************************************************************************************* … … 78 79 * It allocates memory for a remote semaphore in reference cluster, using a RPC if required, 79 80 * and initializes it, using remote accesses from values defined by the <vaddr> and <value> 80 * arguments. It uses also a remote access to return the extended pointer on the semaphore 81 * in the buffer identified by the <buf_xp> argument. 81 * arguments. It register this semaphore in the calling process list of user semaphores. 82 82 ********************************************************************************************* 83 83 * @ vaddr : [in] semaphore virtual address, used as identifier. 84 84 * @ value : [in] semaphore initial value. 85 * @ sem_xp_xp : [out] extended pointer on buffer to store extended pointer on semaphore.86 85 * @ returns 0 if success / returns -1 if no memory. 87 86 ********************************************************************************************/ 88 87 error_t remote_sem_create( intptr_t vaddr, 89 uint32_t value, 90 xptr_t sem_xp_xp ); 88 uint32_t value ); 91 89 92 90 /****************************yy*************************************************************** … … 101 99 /****************************yy*************************************************************** 102 100 * This blocking function implements the SEM_WAIT operation. 103 * - It returns only when the remote semaphore has a non-zero value, 104 * a nd has been atomically decremented.105 * - if the semaphore has a zero value, it register the calling thread in the semaphore106 * 101 * - It returns only when the remote semaphore has a non-zero value, and has been 102 * atomically decremented. 103 * - If the semaphore has a zero value, it register the calling thread in the semaphore 104 * waiting queue, block the thread, and yield. 107 105 ********************************************************************************************* 108 106 * @ sem_xp : [in] extended pointer on semaphore. … … 112 110 /****************************yy*************************************************************** 113 111 * This function mplements the SEM_POST operation. 114 * - It atomically increments the remote semaphore if the semaphore waiting queue is empty.115 * - If the waiting queue is not empty, it wakes up the firstwaiting thread.112 * - It atomically increments the remote semaphore. 113 * - If the waiting queue is not empty, it wakes up all waiting thread. 116 114 ********************************************************************************************* 117 115 * @ sem_xp : [in] extended pointer on semaphore.
Note: See TracChangeset
for help on using the changeset viewer.