wrappthread.c 3.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189
  1. /*
  2. * pthreads wrapper functions.
  3. */
  4. #include "unp.h"
  5. #include "unpthread.h"
  6. void
  7. Pthread_create(pthread_t *tid, const pthread_attr_t *attr,
  8. void * (*func)(void *), void *arg)
  9. {
  10. int n;
  11. if ( (n = pthread_create(tid, attr, func, arg)) == 0)
  12. return;
  13. errno = n;
  14. err_sys("pthread_create error");
  15. }
  16. void
  17. Pthread_join(pthread_t tid, void **status)
  18. {
  19. int n;
  20. if ( (n = pthread_join(tid, status)) == 0)
  21. return;
  22. errno = n;
  23. err_sys("pthread_join error");
  24. }
  25. void
  26. Pthread_detach(pthread_t tid)
  27. {
  28. int n;
  29. if ( (n = pthread_detach(tid)) == 0)
  30. return;
  31. errno = n;
  32. err_sys("pthread_detach error");
  33. }
  34. void
  35. Pthread_kill(pthread_t tid, int signo)
  36. {
  37. int n;
  38. if ( (n = pthread_kill(tid, signo)) == 0)
  39. return;
  40. errno = n;
  41. err_sys("pthread_kill error");
  42. }
  43. void
  44. Pthread_mutexattr_init(pthread_mutexattr_t *attr)
  45. {
  46. int n;
  47. if ( (n = pthread_mutexattr_init(attr)) == 0)
  48. return;
  49. errno = n;
  50. err_sys("pthread_mutexattr_init error");
  51. }
  52. #ifdef _POSIX_THREAD_PROCESS_SHARED
  53. void
  54. Pthread_mutexattr_setpshared(pthread_mutexattr_t *attr, int flag)
  55. {
  56. int n;
  57. if ( (n = pthread_mutexattr_setpshared(attr, flag)) == 0)
  58. return;
  59. errno = n;
  60. err_sys("pthread_mutexattr_setpshared error");
  61. }
  62. #endif
  63. void
  64. Pthread_mutex_init(pthread_mutex_t *mptr, pthread_mutexattr_t *attr)
  65. {
  66. int n;
  67. if ( (n = pthread_mutex_init(mptr, attr)) == 0)
  68. return;
  69. errno = n;
  70. err_sys("pthread_mutex_init error");
  71. }
  72. /* include Pthread_mutex_lock */
  73. void
  74. Pthread_mutex_lock(pthread_mutex_t *mptr)
  75. {
  76. int n;
  77. if ( (n = pthread_mutex_lock(mptr)) == 0)
  78. return;
  79. errno = n;
  80. err_sys("pthread_mutex_lock error");
  81. }
  82. /* end Pthread_mutex_lock */
  83. void
  84. Pthread_mutex_unlock(pthread_mutex_t *mptr)
  85. {
  86. int n;
  87. if ( (n = pthread_mutex_unlock(mptr)) == 0)
  88. return;
  89. errno = n;
  90. err_sys("pthread_mutex_unlock error");
  91. }
  92. void
  93. Pthread_cond_broadcast(pthread_cond_t *cptr)
  94. {
  95. int n;
  96. if ( (n = pthread_cond_broadcast(cptr)) == 0)
  97. return;
  98. errno = n;
  99. err_sys("pthread_cond_broadcast error");
  100. }
  101. void
  102. Pthread_cond_signal(pthread_cond_t *cptr)
  103. {
  104. int n;
  105. if ( (n = pthread_cond_signal(cptr)) == 0)
  106. return;
  107. errno = n;
  108. err_sys("pthread_cond_signal error");
  109. }
  110. void
  111. Pthread_cond_wait(pthread_cond_t *cptr, pthread_mutex_t *mptr)
  112. {
  113. int n;
  114. if ( (n = pthread_cond_wait(cptr, mptr)) == 0)
  115. return;
  116. errno = n;
  117. err_sys("pthread_cond_wait error");
  118. }
  119. void
  120. Pthread_cond_timedwait(pthread_cond_t *cptr, pthread_mutex_t *mptr,
  121. const struct timespec *tsptr)
  122. {
  123. int n;
  124. if ( (n = pthread_cond_timedwait(cptr, mptr, tsptr)) == 0)
  125. return;
  126. errno = n;
  127. err_sys("pthread_cond_timedwait error");
  128. }
  129. void
  130. Pthread_once(pthread_once_t *ptr, void (*func)(void))
  131. {
  132. int n;
  133. if ( (n = pthread_once(ptr, func)) == 0)
  134. return;
  135. errno = n;
  136. err_sys("pthread_once error");
  137. }
  138. void
  139. Pthread_key_create(pthread_key_t *key, void (*func)(void *))
  140. {
  141. int n;
  142. if ( (n = pthread_key_create(key, func)) == 0)
  143. return;
  144. errno = n;
  145. err_sys("pthread_key_create error");
  146. }
  147. void
  148. Pthread_setspecific(pthread_key_t key, const void *value)
  149. {
  150. int n;
  151. if ( (n = pthread_setspecific(key, value)) == 0)
  152. return;
  153. errno = n;
  154. err_sys("pthread_setspecific error");
  155. }