xthread.h 4.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990
  1. /* Support functionality for using threads.
  2. Copyright (C) 2016-2019 Free Software Foundation, Inc.
  3. This file is part of the GNU C Library.
  4. The GNU C Library is free software; you can redistribute it and/or
  5. modify it under the terms of the GNU Lesser General Public
  6. License as published by the Free Software Foundation; either
  7. version 2.1 of the License, or (at your option) any later version.
  8. The GNU C Library is distributed in the hope that it will be useful,
  9. but WITHOUT ANY WARRANTY; without even the implied warranty of
  10. MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
  11. Lesser General Public License for more details.
  12. You should have received a copy of the GNU Lesser General Public
  13. License along with the GNU C Library; if not, see
  14. <http://www.gnu.org/licenses/>. */
  15. #ifndef SUPPORT_THREAD_H
  16. #define SUPPORT_THREAD_H
  17. #include <pthread.h>
  18. #include <sys/cdefs.h>
  19. __BEGIN_DECLS
  20. /* Terminate the process (with exit status 0) after SECONDS have
  21. elapsed, from a helper thread. The process is terminated with the
  22. exit function, so atexit handlers are executed. */
  23. void delayed_exit (int seconds);
  24. /* Terminate the process (with exit status 1) if VALUE is not zero.
  25. In that case, print a failure message to standard output mentioning
  26. FUNCTION. The process is terminated with the exit function, so
  27. atexit handlers are executed. */
  28. void xpthread_check_return (const char *function, int value);
  29. /* The following functions call the corresponding libpthread functions
  30. and terminate the process on error. */
  31. void xpthread_barrier_init (pthread_barrier_t *barrier,
  32. pthread_barrierattr_t *attr, unsigned int count);
  33. void xpthread_barrier_destroy (pthread_barrier_t *barrier);
  34. void xpthread_barrierattr_destroy (pthread_barrierattr_t *);
  35. void xpthread_barrierattr_init (pthread_barrierattr_t *);
  36. void xpthread_barrierattr_setpshared (pthread_barrierattr_t *, int pshared);
  37. void xpthread_mutexattr_destroy (pthread_mutexattr_t *);
  38. void xpthread_mutexattr_init (pthread_mutexattr_t *);
  39. void xpthread_mutexattr_setprotocol (pthread_mutexattr_t *, int);
  40. void xpthread_mutexattr_setpshared (pthread_mutexattr_t *, int);
  41. void xpthread_mutexattr_setrobust (pthread_mutexattr_t *, int);
  42. void xpthread_mutexattr_settype (pthread_mutexattr_t *, int);
  43. void xpthread_mutex_init (pthread_mutex_t *, const pthread_mutexattr_t *);
  44. void xpthread_mutex_destroy (pthread_mutex_t *);
  45. void xpthread_mutex_lock (pthread_mutex_t *mutex);
  46. void xpthread_mutex_unlock (pthread_mutex_t *mutex);
  47. void xpthread_mutex_consistent (pthread_mutex_t *);
  48. void xpthread_spin_lock (pthread_spinlock_t *lock);
  49. void xpthread_spin_unlock (pthread_spinlock_t *lock);
  50. void xpthread_cond_wait (pthread_cond_t * cond, pthread_mutex_t * mutex);
  51. pthread_t xpthread_create (pthread_attr_t *attr,
  52. void *(*thread_func) (void *), void *closure);
  53. void xpthread_detach (pthread_t thr);
  54. void xpthread_cancel (pthread_t thr);
  55. void *xpthread_join (pthread_t thr);
  56. void xpthread_once (pthread_once_t *guard, void (*func) (void));
  57. void xpthread_attr_destroy (pthread_attr_t *attr);
  58. void xpthread_attr_init (pthread_attr_t *attr);
  59. void xpthread_attr_setdetachstate (pthread_attr_t *attr,
  60. int detachstate);
  61. void xpthread_attr_setstacksize (pthread_attr_t *attr,
  62. size_t stacksize);
  63. void xpthread_attr_setguardsize (pthread_attr_t *attr,
  64. size_t guardsize);
  65. /* This function returns non-zero if pthread_barrier_wait returned
  66. PTHREAD_BARRIER_SERIAL_THREAD. */
  67. int xpthread_barrier_wait (pthread_barrier_t *barrier);
  68. void xpthread_rwlock_init (pthread_rwlock_t *rwlock,
  69. const pthread_rwlockattr_t *attr);
  70. void xpthread_rwlockattr_init (pthread_rwlockattr_t *attr);
  71. void xpthread_rwlockattr_setkind_np (pthread_rwlockattr_t *attr, int pref);
  72. void xpthread_rwlock_wrlock (pthread_rwlock_t *rwlock);
  73. void xpthread_rwlock_rdlock (pthread_rwlock_t *rwlock);
  74. void xpthread_rwlock_unlock (pthread_rwlock_t *rwlock);
  75. __END_DECLS
  76. #endif /* SUPPORT_THREAD_H */