semaphore.h 2.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778
  1. /* Copyright (C) 2002, 2003 Free Software Foundation, Inc.
  2. This file is part of the GNU C Library.
  3. The GNU C Library is free software; you can redistribute it and/or
  4. modify it under the terms of the GNU Lesser General Public
  5. License as published by the Free Software Foundation; either
  6. version 2.1 of the License, or (at your option) any later version.
  7. The GNU C Library is distributed in the hope that it will be useful,
  8. but WITHOUT ANY WARRANTY; without even the implied warranty of
  9. MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
  10. Lesser General Public License for more details.
  11. You should have received a copy of the GNU Lesser General Public
  12. License along with the GNU C Library; if not, see
  13. <http://www.gnu.org/licenses/>. */
  14. #ifndef _SEMAPHORE_H
  15. #define _SEMAPHORE_H 1
  16. #include <features.h>
  17. #include <sys/types.h>
  18. #ifdef __USE_XOPEN2K
  19. # define __need_timespec
  20. # include <time.h>
  21. #endif
  22. /* Get the definition for sem_t. */
  23. #include <bits/semaphore.h>
  24. __BEGIN_DECLS
  25. /* Initialize semaphore object SEM to VALUE. If PSHARED then share it
  26. with other processes. */
  27. extern int sem_init (sem_t *__sem, int __pshared, unsigned int __value)
  28. __THROW;
  29. /* Free resources associated with semaphore object SEM. */
  30. extern int sem_destroy (sem_t *__sem) __THROW;
  31. /* Open a named semaphore NAME with open flags OFLAG. */
  32. extern sem_t *sem_open (const char *__name, int __oflag, ...) __THROW;
  33. /* Close descriptor for named semaphore SEM. */
  34. extern int sem_close (sem_t *__sem) __THROW;
  35. /* Remove named semaphore NAME. */
  36. extern int sem_unlink (const char *__name) __THROW;
  37. /* Wait for SEM being posted.
  38. This function is a cancellation point and therefore not marked with
  39. __THROW. */
  40. extern int sem_wait (sem_t *__sem);
  41. #ifdef __USE_XOPEN2K
  42. /* Similar to `sem_wait' but wait only until ABSTIME.
  43. This function is a cancellation point and therefore not marked with
  44. __THROW. */
  45. extern int sem_timedwait (sem_t *__restrict __sem,
  46. const struct timespec *__restrict __abstime);
  47. #endif
  48. /* Test whether SEM is posted. */
  49. extern int sem_trywait (sem_t *__sem) __THROWNL;
  50. /* Post SEM. */
  51. extern int sem_post (sem_t *__sem) __THROWNL;
  52. /* Get current value of SEM and store it in *SVAL. */
  53. extern int sem_getvalue (sem_t *__restrict __sem, int *__restrict __sval)
  54. __THROW;
  55. __END_DECLS
  56. #endif /* semaphore.h */