File indexing completed on 2025-02-22 10:29:21
0001 #ifndef BOOST_THREAD_PTHREAD_PTHREAD_HELPERS_HPP
0002 #define BOOST_THREAD_PTHREAD_PTHREAD_HELPERS_HPP
0003
0004
0005
0006
0007
0008
0009
0010 #include <boost/thread/detail/config.hpp>
0011 #include <boost/throw_exception.hpp>
0012 #include <pthread.h>
0013 #include <errno.h>
0014
0015 #include <boost/config/abi_prefix.hpp>
0016
0017 #ifndef BOOST_THREAD_HAS_NO_EINTR_BUG
0018 #define BOOST_THREAD_HAS_EINTR_BUG
0019 #endif
0020
0021 namespace boost
0022 {
0023 namespace posix
0024 {
0025 BOOST_FORCEINLINE BOOST_THREAD_DISABLE_THREAD_SAFETY_ANALYSIS
0026 int pthread_mutex_init(pthread_mutex_t* m, const pthread_mutexattr_t* attr = NULL)
0027 {
0028 return ::pthread_mutex_init(m, attr);
0029 }
0030
0031 BOOST_FORCEINLINE BOOST_THREAD_DISABLE_THREAD_SAFETY_ANALYSIS
0032 int pthread_cond_init(pthread_cond_t* c)
0033 {
0034 #ifdef BOOST_THREAD_INTERNAL_CLOCK_IS_MONO
0035 pthread_condattr_t attr;
0036 int res = pthread_condattr_init(&attr);
0037 if (res)
0038 {
0039 return res;
0040 }
0041 BOOST_VERIFY(!pthread_condattr_setclock(&attr, CLOCK_MONOTONIC));
0042 res = ::pthread_cond_init(c, &attr);
0043 BOOST_VERIFY(!pthread_condattr_destroy(&attr));
0044 return res;
0045 #else
0046 return ::pthread_cond_init(c, NULL);
0047 #endif
0048 }
0049
0050 #ifdef BOOST_THREAD_HAS_EINTR_BUG
0051 BOOST_FORCEINLINE BOOST_THREAD_DISABLE_THREAD_SAFETY_ANALYSIS
0052 int pthread_mutex_destroy(pthread_mutex_t* m)
0053 {
0054 int ret;
0055 do
0056 {
0057 ret = ::pthread_mutex_destroy(m);
0058 } while (ret == EINTR);
0059 return ret;
0060 }
0061
0062 BOOST_FORCEINLINE BOOST_THREAD_DISABLE_THREAD_SAFETY_ANALYSIS
0063 int pthread_cond_destroy(pthread_cond_t* c)
0064 {
0065 int ret;
0066 do
0067 {
0068 ret = ::pthread_cond_destroy(c);
0069 } while (ret == EINTR);
0070 return ret;
0071 }
0072
0073 BOOST_FORCEINLINE BOOST_THREAD_DISABLE_THREAD_SAFETY_ANALYSIS
0074 int pthread_mutex_lock(pthread_mutex_t* m)
0075 {
0076 int ret;
0077 do
0078 {
0079 ret = ::pthread_mutex_lock(m);
0080 } while (ret == EINTR);
0081 return ret;
0082 }
0083
0084 BOOST_FORCEINLINE BOOST_THREAD_DISABLE_THREAD_SAFETY_ANALYSIS
0085 int pthread_mutex_trylock(pthread_mutex_t* m)
0086 {
0087 int ret;
0088 do
0089 {
0090 ret = ::pthread_mutex_trylock(m);
0091 } while (ret == EINTR);
0092 return ret;
0093 }
0094
0095 BOOST_FORCEINLINE BOOST_THREAD_DISABLE_THREAD_SAFETY_ANALYSIS
0096 int pthread_mutex_unlock(pthread_mutex_t* m)
0097 {
0098 int ret;
0099 do
0100 {
0101 ret = ::pthread_mutex_unlock(m);
0102 } while (ret == EINTR);
0103 return ret;
0104 }
0105
0106 BOOST_FORCEINLINE BOOST_THREAD_DISABLE_THREAD_SAFETY_ANALYSIS
0107 int pthread_cond_wait(pthread_cond_t* c, pthread_mutex_t* m)
0108 {
0109 int ret;
0110 do
0111 {
0112 ret = ::pthread_cond_wait(c, m);
0113 } while (ret == EINTR);
0114 return ret;
0115 }
0116
0117 BOOST_FORCEINLINE BOOST_THREAD_DISABLE_THREAD_SAFETY_ANALYSIS
0118 int pthread_cond_timedwait(pthread_cond_t* c, pthread_mutex_t* m, const struct timespec* t)
0119 {
0120 int ret;
0121 do
0122 {
0123 ret = ::pthread_cond_timedwait(c, m, t);
0124 } while (ret == EINTR);
0125 return ret;
0126 }
0127 #else
0128 BOOST_FORCEINLINE BOOST_THREAD_DISABLE_THREAD_SAFETY_ANALYSIS
0129 int pthread_mutex_destroy(pthread_mutex_t* m)
0130 {
0131 return ::pthread_mutex_destroy(m);
0132 }
0133
0134 BOOST_FORCEINLINE BOOST_THREAD_DISABLE_THREAD_SAFETY_ANALYSIS
0135 int pthread_cond_destroy(pthread_cond_t* c)
0136 {
0137 return ::pthread_cond_destroy(c);
0138 }
0139
0140 BOOST_FORCEINLINE BOOST_THREAD_DISABLE_THREAD_SAFETY_ANALYSIS
0141 int pthread_mutex_lock(pthread_mutex_t* m)
0142 {
0143 return ::pthread_mutex_lock(m);
0144 }
0145
0146 BOOST_FORCEINLINE BOOST_THREAD_DISABLE_THREAD_SAFETY_ANALYSIS
0147 int pthread_mutex_trylock(pthread_mutex_t* m)
0148 {
0149 return ::pthread_mutex_trylock(m);
0150 }
0151
0152 BOOST_FORCEINLINE BOOST_THREAD_DISABLE_THREAD_SAFETY_ANALYSIS
0153 int pthread_mutex_unlock(pthread_mutex_t* m)
0154 {
0155 return ::pthread_mutex_unlock(m);
0156 }
0157
0158 BOOST_FORCEINLINE BOOST_THREAD_DISABLE_THREAD_SAFETY_ANALYSIS
0159 int pthread_cond_wait(pthread_cond_t* c, pthread_mutex_t* m)
0160 {
0161 return ::pthread_cond_wait(c, m);
0162 }
0163
0164 BOOST_FORCEINLINE BOOST_THREAD_DISABLE_THREAD_SAFETY_ANALYSIS
0165 int pthread_cond_timedwait(pthread_cond_t* c, pthread_mutex_t* m, const struct timespec* t)
0166 {
0167 return ::pthread_cond_timedwait(c, m, t);
0168 }
0169 #endif
0170
0171 BOOST_FORCEINLINE BOOST_THREAD_DISABLE_THREAD_SAFETY_ANALYSIS
0172 int pthread_cond_signal(pthread_cond_t* c)
0173 {
0174 return ::pthread_cond_signal(c);
0175 }
0176
0177 BOOST_FORCEINLINE BOOST_THREAD_DISABLE_THREAD_SAFETY_ANALYSIS
0178 int pthread_cond_broadcast(pthread_cond_t* c)
0179 {
0180 return ::pthread_cond_broadcast(c);
0181 }
0182 }
0183 }
0184
0185 #include <boost/config/abi_suffix.hpp>
0186
0187 #endif