pthread_forward.cpp 2.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687
  1. /*
  2. * Copyright (c) 2021, Gunnar Beutner <gunnar@beutner.name>
  3. *
  4. * SPDX-License-Identifier: BSD-2-Clause
  5. */
  6. #include <AK/Assertions.h>
  7. #include <LibC/bits/pthread_forward.h>
  8. static PthreadFunctions s_pthread_functions;
  9. void __init_pthread_forward(PthreadFunctions funcs)
  10. {
  11. s_pthread_functions = funcs;
  12. }
  13. int pthread_mutex_trylock(pthread_mutex_t* mutex)
  14. {
  15. VERIFY(s_pthread_functions.pthread_mutex_trylock);
  16. return s_pthread_functions.pthread_mutex_trylock(mutex);
  17. }
  18. int pthread_mutex_destroy(pthread_mutex_t* mutex)
  19. {
  20. VERIFY(s_pthread_functions.pthread_mutex_destroy);
  21. return s_pthread_functions.pthread_mutex_destroy(mutex);
  22. }
  23. int pthread_mutexattr_init(pthread_mutexattr_t* attr)
  24. {
  25. VERIFY(s_pthread_functions.pthread_mutexattr_init);
  26. return s_pthread_functions.pthread_mutexattr_init(attr);
  27. }
  28. int pthread_mutexattr_settype(pthread_mutexattr_t* attr, int type)
  29. {
  30. VERIFY(s_pthread_functions.pthread_mutexattr_settype);
  31. return s_pthread_functions.pthread_mutexattr_settype(attr, type);
  32. }
  33. int pthread_mutexattr_destroy(pthread_mutexattr_t* attr)
  34. {
  35. VERIFY(s_pthread_functions.pthread_mutexattr_destroy);
  36. return s_pthread_functions.pthread_mutexattr_destroy(attr);
  37. }
  38. int pthread_once(pthread_once_t* self, void (*callback)(void))
  39. {
  40. VERIFY(s_pthread_functions.pthread_once);
  41. return s_pthread_functions.pthread_once(self, callback);
  42. }
  43. int pthread_cond_broadcast(pthread_cond_t* cond)
  44. {
  45. VERIFY(s_pthread_functions.pthread_cond_broadcast);
  46. return s_pthread_functions.pthread_cond_broadcast(cond);
  47. }
  48. int pthread_cond_init(pthread_cond_t* cond, const pthread_condattr_t* attr)
  49. {
  50. VERIFY(s_pthread_functions.pthread_cond_init);
  51. return s_pthread_functions.pthread_cond_init(cond, attr);
  52. }
  53. int pthread_cond_signal(pthread_cond_t* cond)
  54. {
  55. VERIFY(s_pthread_functions.pthread_cond_signal);
  56. return s_pthread_functions.pthread_cond_signal(cond);
  57. }
  58. int pthread_cond_wait(pthread_cond_t* cond, pthread_mutex_t* mutex)
  59. {
  60. VERIFY(s_pthread_functions.pthread_cond_wait);
  61. return s_pthread_functions.pthread_cond_wait(cond, mutex);
  62. }
  63. int pthread_cond_destroy(pthread_cond_t* cond)
  64. {
  65. VERIFY(s_pthread_functions.pthread_cond_destroy);
  66. return s_pthread_functions.pthread_cond_destroy(cond);
  67. }
  68. int pthread_cond_timedwait(pthread_cond_t* cond, pthread_mutex_t* mutex, const struct timespec* abstime)
  69. {
  70. VERIFY(s_pthread_functions.pthread_cond_timedwait);
  71. return s_pthread_functions.pthread_cond_timedwait(cond, mutex, abstime);
  72. }