semaphore.h 2.4 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879
  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, write to the Free
  13. Software Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA
  14. 02111-1307 USA. */
  15. #ifndef _SEMAPHORE_H
  16. #define _SEMAPHORE_H 1
  17. #include <features.h>
  18. #include <sys/types.h>
  19. #ifdef __USE_XOPEN2K
  20. # define __need_timespec
  21. # include <time.h>
  22. #endif
  23. /* Get the definition for sem_t. */
  24. #include <bits/semaphore.h>
  25. __BEGIN_DECLS
  26. /* Initialize semaphore object SEM to VALUE. If PSHARED then share it
  27. with other processes. */
  28. extern int sem_init (sem_t *__sem, int __pshared, unsigned int __value)
  29. __THROW;
  30. /* Free resources associated with semaphore object SEM. */
  31. extern int sem_destroy (sem_t *__sem) __THROW;
  32. /* Open a named semaphore NAME with open flags OFLAG. */
  33. extern sem_t *sem_open (__const char *__name, int __oflag, ...) __THROW;
  34. /* Close descriptor for named semaphore SEM. */
  35. extern int sem_close (sem_t *__sem) __THROW;
  36. /* Remove named semaphore NAME. */
  37. extern int sem_unlink (__const char *__name) __THROW;
  38. /* Wait for SEM being posted.
  39. This function is a cancellation point and therefore not marked with
  40. __THROW. */
  41. extern int sem_wait (sem_t *__sem);
  42. #ifdef __USE_XOPEN2K
  43. /* Similar to `sem_wait' but wait only until ABSTIME.
  44. This function is a cancellation point and therefore not marked with
  45. __THROW. */
  46. extern int sem_timedwait (sem_t *__restrict __sem,
  47. __const struct timespec *__restrict __abstime);
  48. #endif
  49. /* Test whether SEM is posted. */
  50. extern int sem_trywait (sem_t *__sem) __THROW;
  51. /* Post SEM. */
  52. extern int sem_post (sem_t *__sem) __THROW;
  53. /* Get current value of SEM and store it in *SVAL. */
  54. extern int sem_getvalue (sem_t *__restrict __sem, int *__restrict __sval)
  55. __THROW;
  56. __END_DECLS
  57. #endif /* semaphore.h */