williamr@2: /* williamr@2: * Copyright (c) 2005-2009 Nokia Corporation and/or its subsidiary(-ies). williamr@2: * All rights reserved. williamr@2: * This component and the accompanying materials are made available williamr@2: * 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: * which accompanies this distribution, and is available williamr@2: * at the URL "http://www.symbianfoundation.org/legal/licencesv10.html". williamr@2: * williamr@2: * Initial Contributors: williamr@2: * Nokia Corporation - initial contribution. williamr@2: * williamr@2: * Contributors: williamr@2: * williamr@2: * Description: williamr@2: * Name : semaphore.h williamr@2: * Part of : semaphore williamr@2: * Interface : POSIX, semaphores williamr@2: * POSIX implementation of semaphores on Symbian williamr@2: * Version : williamr@2: * All rights reserved. williamr@2: * Redistribution and use in source and binary forms, with or without williamr@2: * modification, are permitted provided that the following conditions are met: williamr@2: * Redistributions of source code must retain the above copyright notice, this williamr@2: * list of conditions and the following disclaimer. williamr@2: * Redistributions in binary form must reproduce the above copyright notice, williamr@2: * this list of conditions and the following disclaimer in the documentation williamr@2: * and/or other materials provided with the distribution. williamr@2: * Neither the name of the nor the names of its contributors williamr@2: * may be used to endorse or promote products derived from this software williamr@2: * without specific prior written permission. williamr@2: * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" williamr@2: * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE williamr@2: * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE williamr@2: * DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE williamr@2: * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL williamr@2: * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR williamr@2: * SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER williamr@2: * CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, williamr@2: * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE williamr@2: * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. williamr@2: * williamr@2: */ williamr@2: williamr@2: williamr@2: williamr@2: #ifndef __SEMAPHORE_H__ williamr@2: #define __SEMAPHORE_H__ williamr@2: williamr@2: #include williamr@2: williamr@2: #ifdef __cplusplus williamr@2: extern "C" williamr@2: { williamr@2: #endif /* __cplusplus */ williamr@2: williamr@2: /*Semaphores supported */ williamr@2: williamr@2: #define SEM_FAILED -1 williamr@2: typedef struct _sem_t* sem_t; williamr@2: williamr@2: /* williamr@2: This function initializes the semaphore object. williamr@2: The semaphore count is set to the initial count value. williamr@2: */ williamr@2: IMPORT_C extern int sem_init (sem_t * sem, int pshared, unsigned int value); williamr@2: williamr@2: /* williamr@2: This function destroys the semaphore object. williamr@2: */ williamr@2: IMPORT_C extern int sem_destroy (sem_t* sem); williamr@2: williamr@2: /* williamr@2: This function atomically decrements sem's count if it is greater than 0 and returns immediately, williamr@2: or it returns immediately with a return code of -1 after having set errno to EAGAIN. williamr@2: sem_trywait never blocks. williamr@2: */ williamr@2: IMPORT_C extern int sem_trywait (sem_t* sem); williamr@2: williamr@2: /* williamr@2: This function atomically decrements sem's count if it is greater than 0 and returns immediately williamr@2: or it suspends the calling thread until it can resume following a call to sem_post or sem_post_multiple williamr@2: */ williamr@2: IMPORT_C extern int sem_wait (sem_t* sem); williamr@2: williamr@2: /* williamr@2: This function atomically decrements sem's count if it is greater than 0 and returns immediately, or it williamr@2: suspends the calling thread. If timeout time lapses before the thread can be resumed because of a sem_post, williamr@2: case, then sem_timedwait returns with a return code of -1 after having set errno to ETIMEDOUT. If the williamr@2: thread can return without suspending then abstime parameter is not checked. williamr@2: */ williamr@2: IMPORT_C extern int sem_timedwait (sem_t* sem, const struct timespec* abstime); williamr@2: williamr@2: /* williamr@2: The function increments (unlocks) the semaphore pointed to by sem . williamr@2: 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: the semaphore will be allowed to return from sem_wait . williamr@2: If successful, the function returns zero; otherwise, it returns -1 and set errno to indicate the error. williamr@2: */ williamr@2: IMPORT_C extern int sem_post (sem_t* sem); williamr@2: williamr@2: /* williamr@2: This function establish a connection between a named semaphore and a process williamr@2: */ williamr@2: /* IMPORT_C extern sem_t* sem_open (const char* name,int oflag,mode_t mode, unsigned int value); */ williamr@2: williamr@2: /* williamr@2: This function indicate that the calling process is finished using the named semaphore indicated by sem*/ williamr@2: /* IMPORT_C extern int sem_close (sem_t* sem); */ williamr@2: williamr@2: /* williamr@2: This function cleans up resources associated with a system-wide semaphore. williamr@2: */ williamr@2: /* IMPORT_C extern int sem_unlink (const char* name); */ williamr@2: williamr@2: /* williamr@2: This function updates the location referenced by the sval argument with the value of the semaphore williamr@2: referenced by sem without affecting the state of the semaphore. williamr@2: The updated value represents an actual semaphore value that occurred at some unspecified time williamr@2: during the call, but it need not be the actual value of the semaphore when it is returned to williamr@2: the calling process. If sem is locked, then the object to which sval points shall either be set williamr@2: to zero or to a negative number whose absolute value represents the number of processes waiting williamr@2: for the semaphore at some unspecified time during the call. williamr@2: */ williamr@2: IMPORT_C extern int sem_getvalue (sem_t* sem, int* sval); williamr@2: williamr@2: williamr@2: #ifdef __cplusplus williamr@2: } /* End of extern "C" */ williamr@2: #endif /* __cplusplus */ williamr@2: williamr@2: #endif /* __SEMAPHORE_H__ */