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.
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@4
     5
* under the terms of "Eclipse Public License v1.0"
williamr@2
     6
* which accompanies this distribution, and is available
williamr@4
     7
* at the URL "http://www.eclipse.org/legal/epl-v10.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@4
    19
* Version     :
williamr@2
    20
*
williamr@2
    21
*/
williamr@2
    22
williamr@2
    23
williamr@2
    24
williamr@2
    25
#ifndef __SEMAPHORE_H__
williamr@2
    26
#define __SEMAPHORE_H__
williamr@2
    27
williamr@2
    28
#include <sys/types.h>
williamr@2
    29
williamr@2
    30
#ifdef __cplusplus
williamr@2
    31
extern "C"
williamr@2
    32
{
williamr@2
    33
#endif              /* __cplusplus */
williamr@2
    34
williamr@2
    35
/*Semaphores supported */
williamr@2
    36
williamr@2
    37
#define SEM_FAILED -1
williamr@2
    38
typedef struct _sem_t* sem_t;
williamr@2
    39
williamr@2
    40
/*
williamr@2
    41
This function initializes the semaphore object.
williamr@2
    42
The semaphore count is set to the initial count value. 
williamr@2
    43
*/
williamr@2
    44
IMPORT_C extern int sem_init (sem_t * sem, int pshared, unsigned int value);
williamr@2
    45
williamr@2
    46
/*
williamr@2
    47
This function destroys the semaphore  object. 
williamr@2
    48
*/
williamr@2
    49
IMPORT_C extern int  sem_destroy (sem_t* sem);
williamr@2
    50
williamr@2
    51
/*
williamr@2
    52
This function atomically decrements sem's count if it is greater than 0 and returns immediately,
williamr@2
    53
or it returns immediately with a return code of -1 after having set errno to EAGAIN. 
williamr@2
    54
sem_trywait never blocks.
williamr@2
    55
*/
williamr@2
    56
IMPORT_C extern int sem_trywait (sem_t* sem);
williamr@2
    57
williamr@2
    58
/*
williamr@2
    59
This function atomically decrements sem's count if it is greater than 0 and returns immediately
williamr@2
    60
or it suspends the calling thread until it can resume following a call to sem_post or sem_post_multiple
williamr@2
    61
*/
williamr@2
    62
IMPORT_C extern int sem_wait (sem_t* sem);
williamr@2
    63
williamr@2
    64
/*
williamr@2
    65
This function atomically decrements sem's count if it is greater than 0 and returns immediately, or it 
williamr@2
    66
suspends the calling thread. If timeout time lapses before the thread can be resumed because of a sem_post,
williamr@2
    67
case, then sem_timedwait returns with a return code of -1 after having set errno to ETIMEDOUT. If the 
williamr@2
    68
thread  can return without suspending then abstime parameter is not checked.
williamr@2
    69
*/
williamr@2
    70
IMPORT_C extern int sem_timedwait (sem_t* sem, const struct timespec* abstime);
williamr@2
    71
williamr@2
    72
/*
williamr@2
    73
The function increments (unlocks) the semaphore pointed to by sem .
williamr@2
    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
williamr@2
    75
the semaphore will be allowed to return from sem_wait .
williamr@2
    76
If successful, the function returns zero; otherwise, it returns -1 and set errno to indicate the error.
williamr@2
    77
*/
williamr@2
    78
IMPORT_C extern int sem_post (sem_t* sem);
williamr@2
    79
williamr@2
    80
/*
williamr@2
    81
This function establish a connection between a named semaphore and a process
williamr@2
    82
*/
williamr@2
    83
/* IMPORT_C extern sem_t* sem_open (const char* name,int oflag,mode_t mode, unsigned int value); */
williamr@2
    84
williamr@2
    85
/*
williamr@2
    86
This function indicate that the calling process is finished using the named semaphore indicated by sem*/
williamr@2
    87
/* IMPORT_C extern int sem_close (sem_t* sem); */
williamr@2
    88
williamr@2
    89
/*
williamr@2
    90
This function cleans up resources associated with a system-wide semaphore.
williamr@2
    91
*/
williamr@2
    92
/* IMPORT_C extern int sem_unlink (const char* name); */
williamr@2
    93
williamr@2
    94
/*
williamr@2
    95
This function updates the location referenced by the sval argument with the value of the semaphore 
williamr@2
    96
referenced by sem without affecting the state of the semaphore. 
williamr@2
    97
The updated value represents an actual semaphore value that occurred at some unspecified time 
williamr@2
    98
during the call, but it need not be the actual value of the semaphore when it is returned to 
williamr@2
    99
the calling process. If sem is locked, then the object to which sval points shall either be set 
williamr@2
   100
to zero or to a negative number whose absolute value represents the number of processes waiting
williamr@2
   101
for the semaphore at some unspecified time during the call.
williamr@2
   102
*/
williamr@2
   103
IMPORT_C extern int sem_getvalue (sem_t* sem, int* sval);
williamr@2
   104
williamr@2
   105
williamr@2
   106
#ifdef __cplusplus
williamr@2
   107
}               /* End of extern "C" */
williamr@2
   108
#endif              /* __cplusplus */
williamr@2
   109
williamr@2
   110
#endif              /* __SEMAPHORE_H__ */