| 1 | /* | 
|---|
| 2 |  * semaphore.h - POSIX semaphore related system calls definition. | 
|---|
| 3 |  *  | 
|---|
| 4 |  * Author    Ghassan Almaless (2008,2009,2010,2011,2012) | 
|---|
| 5 |  *           Alain Greiner    (2016) | 
|---|
| 6 |  * | 
|---|
| 7 |  * Copyright (c) UPMC Sorbonne Universites | 
|---|
| 8 |  * | 
|---|
| 9 |  * This file is part of ALMOS-MKH. | 
|---|
| 10 |  * | 
|---|
| 11 |  * ALMOS-MKH is free software; you can redistribute it and/or modify it | 
|---|
| 12 |  * under the terms of the GNU General Public License as published by | 
|---|
| 13 |  * the Free Software Foundation; version 2.0 of the License. | 
|---|
| 14 |  * | 
|---|
| 15 |  * ALMOS-MKH is distributed in the hope that it will be useful, but | 
|---|
| 16 |  * WITHOUT ANY WARRANTY; without even the implied warranty of | 
|---|
| 17 |  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU | 
|---|
| 18 |  * General Public License for more details. | 
|---|
| 19 |  * | 
|---|
| 20 |  * You should have received a copy of the GNU General Public License | 
|---|
| 21 |  * along with ALMOS-MKH; if not, write to the Free Software Foundation, | 
|---|
| 22 |  * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA | 
|---|
| 23 |  */ | 
|---|
| 24 |  | 
|---|
| 25 | #ifndef _SEMAPHORE_H_ | 
|---|
| 26 | #define _SEMAPHORE_H_ | 
|---|
| 27 |  | 
|---|
| 28 | /********************************************************************************************* | 
|---|
| 29 |  * This defines the user sem_t structure | 
|---|
| 30 |  ********************************************************************************************/ | 
|---|
| 31 |  | 
|---|
| 32 | typedef unsigned long sem_t; | 
|---|
| 33 |  | 
|---|
| 34 | /********************************************************************************************* | 
|---|
| 35 |  * This function initializes a semaphore, defined as a global variable in user process. | 
|---|
| 36 |  ********************************************************************************************* | 
|---|
| 37 |  * @ sem     : pointer on semaphore in user space. | 
|---|
| 38 |  * @ pshared : inter-process semaphore if non-zero. Not supported => must be zero. | 
|---|
| 39 |  * @ value   : semaphore initial value. | 
|---|
| 40 |  * @ returns 0 if success / returns -1 if failure. | 
|---|
| 41 |  ********************************************************************************************/ | 
|---|
| 42 | int sem_init( sem_t      * sem, | 
|---|
| 43 |               int          pshared, | 
|---|
| 44 |               unsigned int value ); | 
|---|
| 45 |  | 
|---|
| 46 | /********************************************************************************************* | 
|---|
| 47 |  * This function destroy a semaphore defined as a global variable in user process. | 
|---|
| 48 |  ********************************************************************************************* | 
|---|
| 49 |  * @ sem     : pointer on semaphore in user space. | 
|---|
| 50 |  * @ returns 0 if success / returns -1 if failure. | 
|---|
| 51 |  ********************************************************************************************/ | 
|---|
| 52 | int sem_destroy( sem_t * sem ); | 
|---|
| 53 |  | 
|---|
| 54 | /********************************************************************************************* | 
|---|
| 55 |  * This function returns in the value buffer the current semaphore current value. | 
|---|
| 56 |  ********************************************************************************************* | 
|---|
| 57 |  * @ sem     : pointer on semaphore in user space. | 
|---|
| 58 |  * @ value   : pointer on buffer for returned value in user space. | 
|---|
| 59 |  * @ returns 0 if success / returns -1 if failure. | 
|---|
| 60 |  ********************************************************************************************/ | 
|---|
| 61 | int sem_getvalue(sem_t *sem, int *value); | 
|---|
| 62 |  | 
|---|
| 63 | /********************************************************************************************* | 
|---|
| 64 |  * This blocking function returns only when the semaphore has been obtained (or if error). | 
|---|
| 65 |  ********************************************************************************************* | 
|---|
| 66 |  * @ sem     : pointer on semaphore in user space. | 
|---|
| 67 |  * @ returns 0 if success / returns -1 if failure. | 
|---|
| 68 |  ********************************************************************************************/ | 
|---|
| 69 | int sem_wait(sem_t *sem); | 
|---|
| 70 |  | 
|---|
| 71 | /********************************************************************************************* | 
|---|
| 72 |  * This function releases a semaphore obtained by a previous sem_wait(). | 
|---|
| 73 |  ********************************************************************************************* | 
|---|
| 74 |  * @ sem     : pointer on semaphore in user space. | 
|---|
| 75 |  * @ returns 0 if success / returns -1 if failure. | 
|---|
| 76 |  ********************************************************************************************/ | 
|---|
| 77 | int sem_post(sem_t *sem); | 
|---|
| 78 |  | 
|---|
| 79 | #endif  /* _SEMAPHORE_H_ */ | 
|---|