gthr.h 5.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154
  1. /* Threads compatibility routines for libgcc2. */
  2. /* Compile this one with gcc. */
  3. /* Copyright (C) 1997-2022 Free Software Foundation, Inc.
  4. This file is part of GCC.
  5. GCC is free software; you can redistribute it and/or modify it under
  6. the terms of the GNU General Public License as published by the Free
  7. Software Foundation; either version 3, or (at your option) any later
  8. version.
  9. GCC is distributed in the hope that it will be useful, but WITHOUT ANY
  10. WARRANTY; without even the implied warranty of MERCHANTABILITY or
  11. FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
  12. for more details.
  13. Under Section 7 of GPL version 3, you are granted additional
  14. permissions described in the GCC Runtime Library Exception, version
  15. 3.1, as published by the Free Software Foundation.
  16. You should have received a copy of the GNU General Public License and
  17. a copy of the GCC Runtime Library Exception along with this program;
  18. see the files COPYING3 and COPYING.RUNTIME respectively. If not, see
  19. <http://www.gnu.org/licenses/>. */
  20. #ifndef GCC_GTHR_H
  21. #define GCC_GTHR_H
  22. #ifndef HIDE_EXPORTS
  23. #pragma GCC visibility push(default)
  24. #endif
  25. /* If this file is compiled with threads support, it must
  26. #define __GTHREADS 1
  27. to indicate that threads support is present. Also it has define
  28. function
  29. int __gthread_active_p ()
  30. that returns 1 if thread system is active, 0 if not.
  31. The threads interface must define the following types:
  32. __gthread_key_t
  33. __gthread_once_t
  34. __gthread_mutex_t
  35. __gthread_recursive_mutex_t
  36. The threads interface must define the following macros:
  37. __GTHREAD_ONCE_INIT
  38. to initialize __gthread_once_t
  39. __GTHREAD_MUTEX_INIT
  40. to initialize __gthread_mutex_t to get a fast
  41. non-recursive mutex.
  42. __GTHREAD_MUTEX_INIT_FUNCTION
  43. to initialize __gthread_mutex_t to get a fast
  44. non-recursive mutex.
  45. Define this to a function which looks like this:
  46. void __GTHREAD_MUTEX_INIT_FUNCTION (__gthread_mutex_t *)
  47. Some systems can't initialize a mutex without a
  48. function call. Don't define __GTHREAD_MUTEX_INIT in this case.
  49. __GTHREAD_RECURSIVE_MUTEX_INIT
  50. __GTHREAD_RECURSIVE_MUTEX_INIT_FUNCTION
  51. as above, but for a recursive mutex.
  52. The threads interface must define the following static functions:
  53. int __gthread_once (__gthread_once_t *once, void (*func) ())
  54. int __gthread_key_create (__gthread_key_t *keyp, void (*dtor) (void *))
  55. int __gthread_key_delete (__gthread_key_t key)
  56. void *__gthread_getspecific (__gthread_key_t key)
  57. int __gthread_setspecific (__gthread_key_t key, const void *ptr)
  58. int __gthread_mutex_destroy (__gthread_mutex_t *mutex);
  59. int __gthread_recursive_mutex_destroy (__gthread_recursive_mutex_t *mutex);
  60. int __gthread_mutex_lock (__gthread_mutex_t *mutex);
  61. int __gthread_mutex_trylock (__gthread_mutex_t *mutex);
  62. int __gthread_mutex_unlock (__gthread_mutex_t *mutex);
  63. int __gthread_recursive_mutex_lock (__gthread_recursive_mutex_t *mutex);
  64. int __gthread_recursive_mutex_trylock (__gthread_recursive_mutex_t *mutex);
  65. int __gthread_recursive_mutex_unlock (__gthread_recursive_mutex_t *mutex);
  66. The following are supported in POSIX threads only. They are required to
  67. fix a deadlock in static initialization inside libsupc++. The header file
  68. gthr-posix.h defines a symbol __GTHREAD_HAS_COND to signify that these extra
  69. features are supported.
  70. Types:
  71. __gthread_cond_t
  72. Macros:
  73. __GTHREAD_COND_INIT
  74. __GTHREAD_COND_INIT_FUNCTION
  75. Interface:
  76. int __gthread_cond_broadcast (__gthread_cond_t *cond);
  77. int __gthread_cond_wait (__gthread_cond_t *cond, __gthread_mutex_t *mutex);
  78. int __gthread_cond_wait_recursive (__gthread_cond_t *cond,
  79. __gthread_recursive_mutex_t *mutex);
  80. All functions returning int should return zero on success or the error
  81. number. If the operation is not supported, -1 is returned.
  82. If the following are also defined, you should
  83. #define __GTHREADS_CXX0X 1
  84. to enable the c++0x thread library.
  85. Types:
  86. __gthread_t
  87. __gthread_time_t
  88. Interface:
  89. int __gthread_create (__gthread_t *thread, void *(*func) (void*),
  90. void *args);
  91. int __gthread_join (__gthread_t thread, void **value_ptr);
  92. int __gthread_detach (__gthread_t thread);
  93. int __gthread_equal (__gthread_t t1, __gthread_t t2);
  94. __gthread_t __gthread_self (void);
  95. int __gthread_yield (void);
  96. int __gthread_mutex_timedlock (__gthread_mutex_t *m,
  97. const __gthread_time_t *abs_timeout);
  98. int __gthread_recursive_mutex_timedlock (__gthread_recursive_mutex_t *m,
  99. const __gthread_time_t *abs_time);
  100. int __gthread_cond_signal (__gthread_cond_t *cond);
  101. int __gthread_cond_timedwait (__gthread_cond_t *cond,
  102. __gthread_mutex_t *mutex,
  103. const __gthread_time_t *abs_timeout);
  104. */
  105. #if SUPPORTS_WEAK
  106. /* The pe-coff weak support isn't fully compatible to ELF's weak.
  107. For static libraries it might would work, but as we need to deal
  108. with shared versions too, we disable it for mingw-targets. */
  109. #ifdef __MINGW32__
  110. #undef GTHREAD_USE_WEAK
  111. #define GTHREAD_USE_WEAK 0
  112. #endif
  113. #ifndef GTHREAD_USE_WEAK
  114. #define GTHREAD_USE_WEAK 1
  115. #endif
  116. #endif
  117. #include "gthr-default.h"
  118. #ifndef HIDE_EXPORTS
  119. #pragma GCC visibility pop
  120. #endif
  121. #endif /* ! GCC_GTHR_H */