williamr@2
|
1 |
/*
|
williamr@2
|
2 |
* Copyright (c) 2005-2009 Nokia Corporation and/or its subsidiary(-ies).
|
williamr@2
|
3 |
* All rights reserved.
|
williamr@2
|
4 |
* This component and the accompanying materials are made available
|
williamr@2
|
5 |
* under the terms of the License "Symbian Foundation License v1.0" to Symbian Foundation members and "Symbian Foundation End User License Agreement v1.0" to non-members
|
williamr@2
|
6 |
* which accompanies this distribution, and is available
|
williamr@2
|
7 |
* at the URL "http://www.symbianfoundation.org/legal/licencesv10.html".
|
williamr@2
|
8 |
*
|
williamr@2
|
9 |
* Initial Contributors:
|
williamr@2
|
10 |
* Nokia Corporation - initial contribution.
|
williamr@2
|
11 |
*
|
williamr@2
|
12 |
* Contributors:
|
williamr@2
|
13 |
*
|
williamr@2
|
14 |
* Description:
|
williamr@2
|
15 |
* Name : semaphore.h
|
williamr@2
|
16 |
* Part of : semaphore
|
williamr@2
|
17 |
* Interface : POSIX, semaphores
|
williamr@2
|
18 |
* POSIX implementation of semaphores on Symbian
|
williamr@2
|
19 |
* Version :
|
williamr@2
|
20 |
* All rights reserved.
|
williamr@2
|
21 |
* Redistribution and use in source and binary forms, with or without
|
williamr@2
|
22 |
* modification, are permitted provided that the following conditions are met:
|
williamr@2
|
23 |
* Redistributions of source code must retain the above copyright notice, this
|
williamr@2
|
24 |
* list of conditions and the following disclaimer.
|
williamr@2
|
25 |
* Redistributions in binary form must reproduce the above copyright notice,
|
williamr@2
|
26 |
* this list of conditions and the following disclaimer in the documentation
|
williamr@2
|
27 |
* and/or other materials provided with the distribution.
|
williamr@2
|
28 |
* Neither the name of the <ORGANIZATION> nor the names of its contributors
|
williamr@2
|
29 |
* may be used to endorse or promote products derived from this software
|
williamr@2
|
30 |
* without specific prior written permission.
|
williamr@2
|
31 |
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
|
williamr@2
|
32 |
* AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
|
williamr@2
|
33 |
* IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
|
williamr@2
|
34 |
* DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE
|
williamr@2
|
35 |
* FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
|
williamr@2
|
36 |
* DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
|
williamr@2
|
37 |
* SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
|
williamr@2
|
38 |
* CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
|
williamr@2
|
39 |
* OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
|
williamr@2
|
40 |
* OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
williamr@2
|
41 |
*
|
williamr@2
|
42 |
*/
|
williamr@2
|
43 |
|
williamr@2
|
44 |
|
williamr@2
|
45 |
|
williamr@2
|
46 |
#ifndef __SEMAPHORE_H__
|
williamr@2
|
47 |
#define __SEMAPHORE_H__
|
williamr@2
|
48 |
|
williamr@2
|
49 |
#include <sys/types.h>
|
williamr@2
|
50 |
|
williamr@2
|
51 |
#ifdef __cplusplus
|
williamr@2
|
52 |
extern "C"
|
williamr@2
|
53 |
{
|
williamr@2
|
54 |
#endif /* __cplusplus */
|
williamr@2
|
55 |
|
williamr@2
|
56 |
/*Semaphores supported */
|
williamr@2
|
57 |
|
williamr@2
|
58 |
#define SEM_FAILED -1
|
williamr@2
|
59 |
typedef struct _sem_t* sem_t;
|
williamr@2
|
60 |
|
williamr@2
|
61 |
/*
|
williamr@2
|
62 |
This function initializes the semaphore object.
|
williamr@2
|
63 |
The semaphore count is set to the initial count value.
|
williamr@2
|
64 |
*/
|
williamr@2
|
65 |
IMPORT_C extern int sem_init (sem_t * sem, int pshared, unsigned int value);
|
williamr@2
|
66 |
|
williamr@2
|
67 |
/*
|
williamr@2
|
68 |
This function destroys the semaphore object.
|
williamr@2
|
69 |
*/
|
williamr@2
|
70 |
IMPORT_C extern int sem_destroy (sem_t* sem);
|
williamr@2
|
71 |
|
williamr@2
|
72 |
/*
|
williamr@2
|
73 |
This function atomically decrements sem's count if it is greater than 0 and returns immediately,
|
williamr@2
|
74 |
or it returns immediately with a return code of -1 after having set errno to EAGAIN.
|
williamr@2
|
75 |
sem_trywait never blocks.
|
williamr@2
|
76 |
*/
|
williamr@2
|
77 |
IMPORT_C extern int sem_trywait (sem_t* sem);
|
williamr@2
|
78 |
|
williamr@2
|
79 |
/*
|
williamr@2
|
80 |
This function atomically decrements sem's count if it is greater than 0 and returns immediately
|
williamr@2
|
81 |
or it suspends the calling thread until it can resume following a call to sem_post or sem_post_multiple
|
williamr@2
|
82 |
*/
|
williamr@2
|
83 |
IMPORT_C extern int sem_wait (sem_t* sem);
|
williamr@2
|
84 |
|
williamr@2
|
85 |
/*
|
williamr@2
|
86 |
This function atomically decrements sem's count if it is greater than 0 and returns immediately, or it
|
williamr@2
|
87 |
suspends the calling thread. If timeout time lapses before the thread can be resumed because of a sem_post,
|
williamr@2
|
88 |
case, then sem_timedwait returns with a return code of -1 after having set errno to ETIMEDOUT. If the
|
williamr@2
|
89 |
thread can return without suspending then abstime parameter is not checked.
|
williamr@2
|
90 |
*/
|
williamr@2
|
91 |
IMPORT_C extern int sem_timedwait (sem_t* sem, const struct timespec* abstime);
|
williamr@2
|
92 |
|
williamr@2
|
93 |
/*
|
williamr@2
|
94 |
The function increments (unlocks) the semaphore pointed to by sem .
|
williamr@2
|
95 |
If there are threads blocked on the semaphore when sem_post is called, the highest priority thread that has been blocked the longest on
|
williamr@2
|
96 |
the semaphore will be allowed to return from sem_wait .
|
williamr@2
|
97 |
If successful, the function returns zero; otherwise, it returns -1 and set errno to indicate the error.
|
williamr@2
|
98 |
*/
|
williamr@2
|
99 |
IMPORT_C extern int sem_post (sem_t* sem);
|
williamr@2
|
100 |
|
williamr@2
|
101 |
/*
|
williamr@2
|
102 |
This function establish a connection between a named semaphore and a process
|
williamr@2
|
103 |
*/
|
williamr@2
|
104 |
/* IMPORT_C extern sem_t* sem_open (const char* name,int oflag,mode_t mode, unsigned int value); */
|
williamr@2
|
105 |
|
williamr@2
|
106 |
/*
|
williamr@2
|
107 |
This function indicate that the calling process is finished using the named semaphore indicated by sem*/
|
williamr@2
|
108 |
/* IMPORT_C extern int sem_close (sem_t* sem); */
|
williamr@2
|
109 |
|
williamr@2
|
110 |
/*
|
williamr@2
|
111 |
This function cleans up resources associated with a system-wide semaphore.
|
williamr@2
|
112 |
*/
|
williamr@2
|
113 |
/* IMPORT_C extern int sem_unlink (const char* name); */
|
williamr@2
|
114 |
|
williamr@2
|
115 |
/*
|
williamr@2
|
116 |
This function updates the location referenced by the sval argument with the value of the semaphore
|
williamr@2
|
117 |
referenced by sem without affecting the state of the semaphore.
|
williamr@2
|
118 |
The updated value represents an actual semaphore value that occurred at some unspecified time
|
williamr@2
|
119 |
during the call, but it need not be the actual value of the semaphore when it is returned to
|
williamr@2
|
120 |
the calling process. If sem is locked, then the object to which sval points shall either be set
|
williamr@2
|
121 |
to zero or to a negative number whose absolute value represents the number of processes waiting
|
williamr@2
|
122 |
for the semaphore at some unspecified time during the call.
|
williamr@2
|
123 |
*/
|
williamr@2
|
124 |
IMPORT_C extern int sem_getvalue (sem_t* sem, int* sval);
|
williamr@2
|
125 |
|
williamr@2
|
126 |
|
williamr@2
|
127 |
#ifdef __cplusplus
|
williamr@2
|
128 |
} /* End of extern "C" */
|
williamr@2
|
129 |
#endif /* __cplusplus */
|
williamr@2
|
130 |
|
williamr@2
|
131 |
#endif /* __SEMAPHORE_H__ */
|