Back to index

glibc  2.9
semaphore.h
Go to the documentation of this file.
00001 /* Copyright (C) 2002, 2003 Free Software Foundation, Inc.
00002    This file is part of the GNU C Library.
00003 
00004    The GNU C Library is free software; you can redistribute it and/or
00005    modify it under the terms of the GNU Lesser General Public
00006    License as published by the Free Software Foundation; either
00007    version 2.1 of the License, or (at your option) any later version.
00008 
00009    The GNU C Library is distributed in the hope that it will be useful,
00010    but WITHOUT ANY WARRANTY; without even the implied warranty of
00011    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
00012    Lesser General Public License for more details.
00013 
00014    You should have received a copy of the GNU Lesser General Public
00015    License along with the GNU C Library; if not, write to the Free
00016    Software Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA
00017    02111-1307 USA.  */
00018 
00019 #ifndef _SEMAPHORE_H
00020 #define _SEMAPHORE_H 1
00021 
00022 #include <features.h>
00023 #include <sys/types.h>
00024 #ifdef __USE_XOPEN2K
00025 # define __need_timespec
00026 # include <time.h>
00027 #endif
00028 
00029 /* Get the definition for sem_t.  */
00030 #include <bits/semaphore.h>
00031 
00032 
00033 __BEGIN_DECLS
00034 
00035 /* Initialize semaphore object SEM to VALUE.  If PSHARED then share it
00036    with other processes.  */
00037 extern int sem_init (sem_t *__sem, int __pshared, unsigned int __value)
00038      __THROW;
00039 /* Free resources associated with semaphore object SEM.  */
00040 extern int sem_destroy (sem_t *__sem) __THROW;
00041 
00042 /* Open a named semaphore NAME with open flags OFLAG.  */
00043 extern sem_t *sem_open (__const char *__name, int __oflag, ...) __THROW;
00044 
00045 /* Close descriptor for named semaphore SEM.  */
00046 extern int sem_close (sem_t *__sem) __THROW;
00047 
00048 /* Remove named semaphore NAME.  */
00049 extern int sem_unlink (__const char *__name) __THROW;
00050 
00051 /* Wait for SEM being posted.
00052 
00053    This function is a cancellation point and therefore not marked with
00054    __THROW.  */
00055 extern int sem_wait (sem_t *__sem);
00056 
00057 #ifdef __USE_XOPEN2K
00058 /* Similar to `sem_wait' but wait only until ABSTIME.
00059 
00060    This function is a cancellation point and therefore not marked with
00061    __THROW.  */
00062 extern int sem_timedwait (sem_t *__restrict __sem,
00063                        __const struct timespec *__restrict __abstime);
00064 #endif
00065 
00066 /* Test whether SEM is posted.  */
00067 extern int sem_trywait (sem_t *__sem) __THROW;
00068 
00069 /* Post SEM.  */
00070 extern int sem_post (sem_t *__sem) __THROW;
00071 
00072 /* Get current value of SEM and store it in *SVAL.  */
00073 extern int sem_getvalue (sem_t *__restrict __sem, int *__restrict __sval)
00074      __THROW;
00075 
00076 
00077 __END_DECLS
00078 
00079 #endif /* semaphore.h */