Files
glibc/linuxthreads/semaphore.h
T

88 lines
2.8 KiB
C
Raw Normal View History

1998-03-11 12:42:25 +00:00
/* Linuxthreads - a simple clone()-based implementation of Posix */
/* threads for Linux. */
/* Copyright (C) 1996 Xavier Leroy (Xavier.Leroy@inria.fr) */
/* */
/* This program is free software; you can redistribute it and/or */
/* modify it under the terms of the GNU Library General Public License */
/* as published by the Free Software Foundation; either version 2 */
/* of the License, or (at your option) any later version. */
/* */
/* This program is distributed in the hope that it will be useful, */
/* but WITHOUT ANY WARRANTY; without even the implied warranty of */
/* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the */
/* GNU Library General Public License for more details. */
#ifndef _SEMAPHORE_H
#define _SEMAPHORE_H 1
#include <features.h>
1998-10-05 13:40:47 +00:00
#include <sys/types.h>
2000-03-27 05:36:34 +00:00
#ifdef __USE_XOPEN2K
# define __need_timespec
# include <time.h>
#endif
1998-03-11 12:42:25 +00:00
1999-04-15 13:54:57 +00:00
#ifndef _PTHREAD_DESCR_DEFINED
/* Thread descriptors. Needed for `sem_t' definition. */
typedef struct _pthread_descr_struct *_pthread_descr;
# define _PTHREAD_DESCR_DEFINED
#endif
1998-03-11 12:42:25 +00:00
1999-04-15 13:54:57 +00:00
/* System specific semaphore definition. */
typedef struct
{
struct _pthread_fastlock __sem_lock;
1999-04-15 13:54:57 +00:00
int __sem_value;
_pthread_descr __sem_waiting;
} sem_t;
1998-03-11 12:42:25 +00:00
1999-04-15 13:54:57 +00:00
/* Value returned if `sem_open' failed. */
2000-02-23 02:45:25 +00:00
#define SEM_FAILED ((sem_t *) 0)
1999-04-15 13:54:57 +00:00
/* Maximum value the semaphore can have. */
2004-04-17 23:14:52 +00:00
#define SEM_VALUE_MAX (2147483647)
1999-04-15 13:54:57 +00:00
1998-03-11 12:42:25 +00:00
__BEGIN_DECLS
1999-04-15 13:54:57 +00:00
/* Initialize semaphore object SEM to VALUE. If PSHARED then share it
with other processes. */
1999-10-25 20:18:27 +00:00
extern int sem_init (sem_t *__sem, int __pshared, unsigned int __value) __THROW;
1999-04-15 13:54:57 +00:00
/* Free resources associated with semaphore object SEM. */
1999-10-25 20:18:27 +00:00
extern int sem_destroy (sem_t *__sem) __THROW;
1999-04-15 13:54:57 +00:00
/* Open a named semaphore NAME with open flaot OFLAG. */
1999-10-25 20:18:27 +00:00
extern sem_t *sem_open (__const char *__name, int __oflag, ...) __THROW;
1999-04-15 13:54:57 +00:00
/* Close descriptor for named semaphore SEM. */
1999-10-25 20:18:27 +00:00
extern int sem_close (sem_t *__sem) __THROW;
1999-04-15 13:54:57 +00:00
/* Remove named semaphore NAME. */
1999-10-25 20:18:27 +00:00
extern int sem_unlink (__const char *__name) __THROW;
1999-04-15 13:54:57 +00:00
/* Wait for SEM being posted. */
2003-12-27 06:08:32 +00:00
extern int sem_wait (sem_t *__sem);
1999-04-15 13:54:57 +00:00
2000-03-27 05:36:34 +00:00
#ifdef __USE_XOPEN2K
/* Similar to `sem_wait' but wait only until ABSTIME. */
2000-08-21 06:49:52 +00:00
extern int sem_timedwait (sem_t *__restrict __sem,
2003-12-27 06:08:32 +00:00
__const struct timespec *__restrict __abstime);
2000-03-27 05:36:34 +00:00
#endif
1999-04-15 13:54:57 +00:00
/* Test whether SEM is posted. */
1999-10-25 20:18:27 +00:00
extern int sem_trywait (sem_t *__sem) __THROW;
1999-04-15 13:54:57 +00:00
/* Post SEM. */
1999-10-25 20:18:27 +00:00
extern int sem_post (sem_t *__sem) __THROW;
1999-04-15 13:54:57 +00:00
/* Get current value of SEM and store it in *SVAL. */
2000-08-21 06:49:52 +00:00
extern int sem_getvalue (sem_t *__restrict __sem, int *__restrict __sval)
__THROW;
1998-03-11 12:42:25 +00:00
__END_DECLS
#endif /* semaphore.h */