epoc32/include/stdapis/semaphore.h
author William Roberts <williamr@symbian.org>
Wed, 31 Mar 2010 12:33:34 +0100
branchSymbian3
changeset 4 837f303aceeb
parent 2 2fe1408b6811
permissions -rw-r--r--
Current Symbian^3 public API header files (from PDK 3.0.h)
This is the epoc32/include tree with the "platform" subtrees removed, and
all but a selected few mbg and rsg files removed.
     1 /*
     2 * Copyright (c) 2005-2009 Nokia Corporation and/or its subsidiary(-ies).
     3 * All rights reserved.
     4 * This component and the accompanying materials are made available
     5 * under the terms of "Eclipse Public License v1.0"
     6 * which accompanies this distribution, and is available
     7 * at the URL "http://www.eclipse.org/legal/epl-v10.html".
     8 *
     9 * Initial Contributors:
    10 * Nokia Corporation - initial contribution.
    11 *
    12 * Contributors:
    13 *
    14 * Description:
    15 * Name        : semaphore.h
    16 * Part of     : semaphore
    17 * Interface   : POSIX, semaphores
    18 * POSIX implementation of semaphores on Symbian
    19 * Version     :
    20 *
    21 */
    22 
    23 
    24 
    25 #ifndef __SEMAPHORE_H__
    26 #define __SEMAPHORE_H__
    27 
    28 #include <sys/types.h>
    29 
    30 #ifdef __cplusplus
    31 extern "C"
    32 {
    33 #endif              /* __cplusplus */
    34 
    35 /*Semaphores supported */
    36 
    37 #define SEM_FAILED -1
    38 typedef struct _sem_t* sem_t;
    39 
    40 /*
    41 This function initializes the semaphore object.
    42 The semaphore count is set to the initial count value. 
    43 */
    44 IMPORT_C extern int sem_init (sem_t * sem, int pshared, unsigned int value);
    45 
    46 /*
    47 This function destroys the semaphore  object. 
    48 */
    49 IMPORT_C extern int  sem_destroy (sem_t* sem);
    50 
    51 /*
    52 This function atomically decrements sem's count if it is greater than 0 and returns immediately,
    53 or it returns immediately with a return code of -1 after having set errno to EAGAIN. 
    54 sem_trywait never blocks.
    55 */
    56 IMPORT_C extern int sem_trywait (sem_t* sem);
    57 
    58 /*
    59 This function atomically decrements sem's count if it is greater than 0 and returns immediately
    60 or it suspends the calling thread until it can resume following a call to sem_post or sem_post_multiple
    61 */
    62 IMPORT_C extern int sem_wait (sem_t* sem);
    63 
    64 /*
    65 This function atomically decrements sem's count if it is greater than 0 and returns immediately, or it 
    66 suspends the calling thread. If timeout time lapses before the thread can be resumed because of a sem_post,
    67 case, then sem_timedwait returns with a return code of -1 after having set errno to ETIMEDOUT. If the 
    68 thread  can return without suspending then abstime parameter is not checked.
    69 */
    70 IMPORT_C extern int sem_timedwait (sem_t* sem, const struct timespec* abstime);
    71 
    72 /*
    73 The function increments (unlocks) the semaphore pointed to by sem .
    74 If there are threads blocked on the semaphore when sem_post is called, the highest priority thread that has been blocked the longest on
    75 the semaphore will be allowed to return from sem_wait .
    76 If successful, the function returns zero; otherwise, it returns -1 and set errno to indicate the error.
    77 */
    78 IMPORT_C extern int sem_post (sem_t* sem);
    79 
    80 /*
    81 This function establish a connection between a named semaphore and a process
    82 */
    83 /* IMPORT_C extern sem_t* sem_open (const char* name,int oflag,mode_t mode, unsigned int value); */
    84 
    85 /*
    86 This function indicate that the calling process is finished using the named semaphore indicated by sem*/
    87 /* IMPORT_C extern int sem_close (sem_t* sem); */
    88 
    89 /*
    90 This function cleans up resources associated with a system-wide semaphore.
    91 */
    92 /* IMPORT_C extern int sem_unlink (const char* name); */
    93 
    94 /*
    95 This function updates the location referenced by the sval argument with the value of the semaphore 
    96 referenced by sem without affecting the state of the semaphore. 
    97 The updated value represents an actual semaphore value that occurred at some unspecified time 
    98 during the call, but it need not be the actual value of the semaphore when it is returned to 
    99 the calling process. If sem is locked, then the object to which sval points shall either be set 
   100 to zero or to a negative number whose absolute value represents the number of processes waiting
   101 for the semaphore at some unspecified time during the call.
   102 */
   103 IMPORT_C extern int sem_getvalue (sem_t* sem, int* sval);
   104 
   105 
   106 #ifdef __cplusplus
   107 }               /* End of extern "C" */
   108 #endif              /* __cplusplus */
   109 
   110 #endif              /* __SEMAPHORE_H__ */