semaphore.h

Go to the documentation of this file.
00001 /*
00002 * ==============================================================================
00003 *  Name        : semaphore.h
00004 *  Part of     : semaphore
00005 *  Interface   : POSIX, semaphores
00006 *  Description : POSIX implementation of semaphores on Symbian
00007 *  Version     : 
00008 
00009 Copyright © 2005-2006 Nokia Corporation
00010 All rights reserved.
00011 
00012 Redistribution and use in source and binary forms, with or without 
00013 modification, are permitted provided that the following conditions are met:
00014  * Redistributions of source code must retain the above copyright notice, this 
00015    list of conditions and the following disclaimer. 
00016  * Redistributions in binary form must reproduce the above copyright notice, 
00017    this list of conditions and the following disclaimer in the documentation 
00018    and/or other materials provided with the distribution. 
00019  * Neither the name of the <ORGANIZATION> nor the names of its contributors 
00020    may be used to endorse or promote products derived from this software 
00021    without specific prior written permission. 
00022    
00023 THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" 
00024 AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE 
00025 IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE 
00026 DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE
00027 FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL 
00028 DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR 
00029 SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER 
00030 CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
00031 OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE 
00032 OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
00033 * ==============================================================================
00034 */
00035 #ifndef __SEMAPHORE_H__
00036 #define __SEMAPHORE_H__
00037 
00038 #include <_ansi.h>
00039 #include <sys/types.h>
00040 
00041 #ifdef __cplusplus
00042 extern "C"
00043 {
00044 #endif              /* __cplusplus */
00045 
00046 /*Semaphores supported */
00047 
00048 #define SEM_FAILED -1
00049 typedef struct _sem_t* sem_t;
00050 
00051 /*
00052 This function initializes the semaphore object.
00053 The semaphore count is set to the initial count value. 
00054 */
00055 IMPORT_C extern int sem_init (sem_t * sem, int pshared, unsigned int value);
00056 
00057 /*
00058 This function destroys the semaphore  object. 
00059 */
00060 IMPORT_C extern int  sem_destroy (sem_t* sem);
00061 
00062 /*
00063 This function atomically decrements sem's count if it is greater than 0 and returns immediately,
00064 or it returns immediately with a return code of -1 after having set errno to EAGAIN. 
00065 sem_trywait never blocks.
00066 */
00067 IMPORT_C extern int sem_trywait (sem_t* sem);
00068 
00069 /*
00070 This function atomically decrements sem's count if it is greater than 0 and returns immediately
00071 or it suspends the calling thread until it can resume following a call to sem_post or sem_post_multiple
00072 */
00073 IMPORT_C extern int sem_wait (sem_t* sem);
00074 
00075 /*
00076 This function atomically decrements sem's count if it is greater than 0 and returns immediately, or it 
00077 suspends the calling thread. If timeout time lapses before the thread can be resumed because of a sem_post,
00078 case, then sem_timedwait returns with a return code of -1 after having set errno to ETIMEDOUT. If the 
00079 thread  can return without suspending then abstime parameter is not checked.
00080 */
00081 IMPORT_C extern int sem_timedwait (sem_t* sem, const struct timespec* abstime);
00082 
00083 /*
00084 This function atomically decrements sem's count if it is greater than 0 and returns immediately, or it 
00085 suspends the calling thread. If timeout time lapses before the thread can be resumed because of a sem_post,
00086 case, then sem_timedwait returns with a return code of -1 after having set errno to ETIMEDOUT. If the 
00087 thread  can return without suspending then abstime parameter is not checked.
00088 */
00089 IMPORT_C extern int sem_post (sem_t* sem);
00090 
00091 /*
00092 This function establish a connection between a named semaphore and a process
00093 */
00094 /* IMPORT_C extern sem_t* sem_open (const char* name,int oflag,mode_t mode, unsigned int value); */
00095 
00096 /*
00097 This function indicate that the calling process is finished using the named semaphore indicated by sem*/
00098 /* IMPORT_C extern int sem_close (sem_t* sem); */
00099 
00100 /*
00101 This function cleans up resources associated with a system-wide semaphore.
00102 */
00103 /* IMPORT_C extern int sem_unlink (const char* name); */
00104 
00105 /*
00106 This function updates the location referenced by the sval argument with the value of the semaphore 
00107 referenced by sem without affecting the state of the semaphore. 
00108 The updated value represents an actual semaphore value that occurred at some unspecified time 
00109 during the call, but it need not be the actual value of the semaphore when it is returned to 
00110 the calling process. If sem is locked, then the object to which sval points shall either be set 
00111 to zero or to a negative number whose absolute value represents the number of processes waiting
00112 for the semaphore at some unspecified time during the call.
00113 */
00114 IMPORT_C extern int sem_getvalue (sem_t* sem, int* sval);
00115 
00116 
00117 #ifdef __cplusplus
00118 }               /* End of extern "C" */
00119 #endif              /* __cplusplus */
00120 
00121 #endif              /* __SEMAPHORE_H__ */

Copyright © Nokia Corporation 2001-2008
Back to top