30#define _CONCURRENCE_H 1
32#pragma GCC system_header
40namespace __gnu_cxx _GLIBCXX_VISIBILITY(default)
42_GLIBCXX_BEGIN_NAMESPACE_VERSION
49 enum _Lock_policy { _S_single, _S_mutex, _S_atomic };
53 static const _Lock_policy __default_lock_policy =
56#elif defined _GLIBCXX_HAVE_ATOMIC_LOCK_POLICY
69 {
return "__gnu_cxx::__concurrence_lock_error"; }
77 {
return "__gnu_cxx::__concurrence_unlock_error"; }
85 {
return "__gnu_cxx::__concurrence_broadcast_error"; }
93 {
return "__gnu_cxx::__concurrence_wait_error"; }
98 __throw_concurrence_lock_error()
99 { _GLIBCXX_THROW_OR_ABORT(__concurrence_lock_error()); }
102 __throw_concurrence_unlock_error()
103 { _GLIBCXX_THROW_OR_ABORT(__concurrence_unlock_error()); }
105#ifdef __GTHREAD_HAS_COND
107 __throw_concurrence_broadcast_error()
108 { _GLIBCXX_THROW_OR_ABORT(__concurrence_broadcast_error()); }
111 __throw_concurrence_wait_error()
112 { _GLIBCXX_THROW_OR_ABORT(__concurrence_wait_error()); }
118#if __GTHREADS && defined __GTHREAD_MUTEX_INIT
119 __gthread_mutex_t _M_mutex = __GTHREAD_MUTEX_INIT;
121 __gthread_mutex_t _M_mutex;
124 __mutex(
const __mutex&);
125 __mutex& operator=(
const __mutex&);
130#if __GTHREADS && ! defined __GTHREAD_MUTEX_INIT
131 if (__gthread_active_p())
132 __GTHREAD_MUTEX_INIT_FUNCTION(&_M_mutex);
136#if __GTHREADS && ! defined __GTHREAD_MUTEX_INIT
139 if (__gthread_active_p())
140 __gthread_mutex_destroy(&_M_mutex);
147 if (__gthread_active_p())
149 if (__gthread_mutex_lock(&_M_mutex) != 0)
150 __throw_concurrence_lock_error();
158 if (__gthread_active_p())
160 if (__gthread_mutex_unlock(&_M_mutex) != 0)
161 __throw_concurrence_unlock_error();
166 __gthread_mutex_t* gthread_mutex(
void)
167 {
return &_M_mutex; }
170 class __recursive_mutex
173#if __GTHREADS && defined __GTHREAD_RECURSIVE_MUTEX_INIT
174 __gthread_recursive_mutex_t _M_mutex = __GTHREAD_RECURSIVE_MUTEX_INIT;
176 __gthread_recursive_mutex_t _M_mutex;
179 __recursive_mutex(
const __recursive_mutex&);
180 __recursive_mutex& operator=(
const __recursive_mutex&);
185#if __GTHREADS && ! defined __GTHREAD_RECURSIVE_MUTEX_INIT
186 if (__gthread_active_p())
187 __GTHREAD_RECURSIVE_MUTEX_INIT_FUNCTION(&_M_mutex);
191#if __GTHREADS && ! defined __GTHREAD_RECURSIVE_MUTEX_INIT
194 if (__gthread_active_p())
195 __gthread_recursive_mutex_destroy(&_M_mutex);
202 if (__gthread_active_p())
204 if (__gthread_recursive_mutex_lock(&_M_mutex) != 0)
205 __throw_concurrence_lock_error();
213 if (__gthread_active_p())
215 if (__gthread_recursive_mutex_unlock(&_M_mutex) != 0)
216 __throw_concurrence_unlock_error();
221 __gthread_recursive_mutex_t* gthread_recursive_mutex(
void)
222 {
return &_M_mutex; }
231 typedef __mutex __mutex_type;
234 __mutex_type& _M_device;
240 explicit __scoped_lock(__mutex_type& __name) : _M_device(__name)
241 { _M_device.lock(); }
244 { _M_device.unlock(); }
247#ifdef __GTHREAD_HAS_COND
251#if __GTHREADS && defined __GTHREAD_COND_INIT
252 __gthread_cond_t _M_cond = __GTHREAD_COND_INIT;
254 __gthread_cond_t _M_cond;
257 __cond(
const __cond&);
258 __cond& operator=(
const __cond&);
263#if __GTHREADS && ! defined __GTHREAD_COND_INIT
264 if (__gthread_active_p())
265 __GTHREAD_COND_INIT_FUNCTION(&_M_cond);
269#if __GTHREADS && ! defined __GTHREAD_COND_INIT
272 if (__gthread_active_p())
273 __gthread_cond_destroy(&_M_cond);
280 if (__gthread_active_p())
282 if (__gthread_cond_broadcast(&_M_cond) != 0)
283 __throw_concurrence_broadcast_error();
288 void wait(__mutex *mutex)
292 if (__gthread_cond_wait(&_M_cond, mutex->gthread_mutex()) != 0)
293 __throw_concurrence_wait_error();
298 void wait_recursive(__recursive_mutex *mutex)
302 if (__gthread_cond_wait_recursive(&_M_cond,
303 mutex->gthread_recursive_mutex())
305 __throw_concurrence_wait_error();
312_GLIBCXX_END_NAMESPACE_VERSION
void lock(_L1 &__l1, _L2 &__l2, _L3 &... __l3)
Generic lock.
GNU extensions for public use.
Base class for all library exceptions.