semaphore.h 2.5 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980
  1. /* Linuxthreads - a simple clone()-based implementation of Posix */
  2. /* threads for Linux. */
  3. /* Copyright (C) 1996 Xavier Leroy (Xavier.Leroy@inria.fr) */
  4. /* */
  5. /* This program is free software; you can redistribute it and/or */
  6. /* modify it under the terms of the GNU Library General Public License */
  7. /* as published by the Free Software Foundation; either version 2 */
  8. /* of the License, or (at your option) any later version. */
  9. /* */
  10. /* This program is distributed in the hope that it will be useful, */
  11. /* but WITHOUT ANY WARRANTY; without even the implied warranty of */
  12. /* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the */
  13. /* GNU Library General Public License for more details. */
  14. #ifndef _SEMAPHORE_H
  15. #define _SEMAPHORE_H 1
  16. #include <features.h>
  17. #include <sys/types.h>
  18. #ifndef _PTHREAD_DESCR_DEFINED
  19. /* Thread descriptors. Needed for `sem_t' definition. */
  20. typedef struct _pthread_descr_struct *_pthread_descr;
  21. # define _PTHREAD_DESCR_DEFINED
  22. #endif
  23. /* System specific semaphore definition. */
  24. typedef struct
  25. {
  26. struct
  27. {
  28. long int status;
  29. int spinlock;
  30. } __sem_lock;
  31. int __sem_value;
  32. _pthread_descr __sem_waiting;
  33. } sem_t;
  34. /* Value returned if `sem_open' failed. */
  35. #define SEM_FAILED ((sem_t *) 0)
  36. /* Maximum value the semaphore can have. */
  37. #define SEM_VALUE_MAX ((int) ((~0u) >> 1))
  38. __BEGIN_DECLS
  39. /* Initialize semaphore object SEM to VALUE. If PSHARED then share it
  40. with other processes. */
  41. extern int sem_init __P ((sem_t *__sem, int __pshared, unsigned int __value));
  42. /* Free resources associated with semaphore object SEM. */
  43. extern int sem_destroy __P ((sem_t *__sem));
  44. /* Open a named semaphore NAME with open flaot OFLAG. */
  45. extern sem_t *sem_open __P ((__const char *__name, int __oflag, ...));
  46. /* Close descriptor for named semaphore SEM. */
  47. extern int sem_close __P ((sem_t *__sem));
  48. /* Remove named semaphore NAME. */
  49. extern int sem_unlink __P ((__const char *__name));
  50. /* Wait for SEM being posted. */
  51. extern int sem_wait __P ((sem_t *__sem));
  52. /* Test whether SEM is posted. */
  53. extern int sem_trywait __P ((sem_t *__sem));
  54. /* Post SEM. */
  55. extern int sem_post __P ((sem_t *__sem));
  56. /* Get current value of SEM and store it in *SVAL. */
  57. extern int sem_getvalue __P ((sem_t *__sem, int *__sval));
  58. __END_DECLS
  59. #endif /* semaphore.h */