source: trunk/libs/libsemaphore/semaphore.h @ 555

Last change on this file since 555 was 469, checked in by alain, 6 years ago

1) Introduce the libsemaphore library.
2) Introduce a small libmath library, required by the "fft" application..
3) Introduce the multithreaded "fft" application.
4) Fix a bad synchronisation bug in the Copy-On-Write mechanism.

File size: 4.4 KB
Line 
1/*
2 * pthread.h - User level <semaphore> library definition.
3 *
4 * Author     Alain Greiner (2016,2017)
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 _SEMAPHORE_H_
25#define _SEMAPHORE_H_
26
27//////////////////////////////////////////////////////////////////////////////////////////////
28//             POSIX unnamed semaphores related functions
29//////////////////////////////////////////////////////////////////////////////////////////////
30
31#include <shared_semaphore.h>
32
33/*********************************************************************************************
34 * This function initializes an unnamed semaphore.
35 * Process shared semaphores are not supported in this implementation.
36 * Initializing a semaphore that has already been initialized results in undefined behavior.
37 *********************************************************************************************
38 * @ sem         : [in]  pointer on semaphore.
39 * @ pshared     : [in]  unsupported => must be zero.
40 * @ value       : [in]  initial semaphore value.
41 * @ return 0 if success / return -1 if failure.
42 ********************************************************************************************/
43int sem_init( sem_t        * sem,
44              int            pshared,
45              unsigned int   value );
46
47/*********************************************************************************************
48 * This blocking function locks a semaphore. It decrements the semaphore pointed to by <sem>.
49 * If the semaphore's value is greater than zero, then the decrement proceeds, and the
50 * function returns immediately. If the semaphore currently has the value zero, then the call
51 * blocks until it becomes possible to perform the decrement.
52 *********************************************************************************************
53 * @ sem         : [in]  pointer on semaphore.
54 * @ return 0 if success / return -1 if failure.
55 ********************************************************************************************/
56int sem_wait( sem_t * sem );
57
58/*********************************************************************************************
59 * This function unlocks a semaphore. It increments the semaphore pointed to by <sem>.
60 * If the semaphore's value consequently becomes greater than zero, then another thread
61 * blocked in a sem_wait() call will be woken up and proceed to lock the semaphore.
62 *********************************************************************************************
63 * @ sem         : [in]  pointer on semaphore.
64 * @ return 0 if success / return -1 if failure.
65 ********************************************************************************************/
66int sem_post( sem_t * sem );
67
68/*********************************************************************************************
69 * This function destroys the semaphore pointed to by <sem>.
70 *********************************************************************************************
71 * @ sem         : [in]  pointer on semaphore.
72 * @ return 0 if success / return -1 if failure.
73 ********************************************************************************************/
74int sem_destroy( sem_t * sem );
75
76/*********************************************************************************************
77 * This function places the current value of the semaphore pointed to by <sem>
78 * into the integer pointed to by <sval>.
79 *********************************************************************************************
80 * @ sem         : [in]  pointer on semaphore.
81 * @ value       : [out] buffer for semaphore current value.
82 * @ return 0 if success / return -1 if failure.
83 ********************************************************************************************/
84int sem_getvalue( sem_t * sem,
85                  int   * value );
86
87
88#endif  // _SEMAPHORE_H_
Note: See TracBrowser for help on using the repository browser.