* @{
*/
+ /// cv_status
+ enum class cv_status { no_timeout, timeout };
+
/// condition_variable
class condition_variable
{
}
template<typename _Duration>
- bool
+ cv_status
wait_until(unique_lock<mutex>& __lock,
const chrono::time_point<__clock_t, _Duration>& __atime)
{ return __wait_until_impl(__lock, __atime); }
template<typename _Clock, typename _Duration>
- bool
+ cv_status
wait_until(unique_lock<mutex>& __lock,
const chrono::time_point<_Clock, _Duration>& __atime)
{
_Predicate __p)
{
while (!__p())
- if (!wait_until(__lock, __atime))
+ if (wait_until(__lock, __atime) == cv_status::timeout)
return __p();
return true;
}
template<typename _Rep, typename _Period>
- bool
+ cv_status
wait_for(unique_lock<mutex>& __lock,
const chrono::duration<_Rep, _Period>& __rtime)
{ return wait_until(__lock, __clock_t::now() + __rtime); }
private:
template<typename _Clock, typename _Duration>
- bool
+ cv_status
__wait_until_impl(unique_lock<mutex>& __lock,
const chrono::time_point<_Clock, _Duration>& __atime)
{
__gthread_cond_timedwait(&_M_cond, __lock.mutex()->native_handle(),
&__ts);
- return _Clock::now() < __atime;
+ return (_Clock::now() < __atime
+ ? cv_status::no_timeout : cv_status::timeout);
}
};
wait(_Lock& __lock, _Predicate __p);
template<typename _Lock, typename _Clock, typename _Duration>
- bool
+ cv_status
wait_until(_Lock& __lock,
const chrono::time_point<_Clock, _Duration>& __atime);
_Predicate __p);
template<typename _Lock, typename _Rep, typename _Period>
- bool
+ cv_status
wait_for(_Lock& __lock, const chrono::duration<_Rep, _Period>& __rtime);
template<typename _Lock, typename _Rep,
locale::locale() throw() : _M_impl(0)
{
_S_initialize();
- __gnu_cxx::__scoped_lock sentry(get_locale_mutex());
- _S_global->_M_add_reference();
+
+ // Checked locking to optimize the common case where _S_global
+ // still points to _S_classic (locale::_S_initialize_once()):
+ // - If they are the same, just increment the reference count and
+ // we are done. This effectively constructs a C locale object
+ // identical to the static c_locale.
+ // - Otherwise, _S_global can and may be destroyed due to
+ // locale::global() call on another thread, in which case we
+ // fall back to lock protected access to both _S_global and
+ // its reference count.
_M_impl = _S_global;
+ if (_M_impl == _S_classic)
+ _M_impl->_M_add_reference();
+ else
+ {
+ __gnu_cxx::__scoped_lock sentry(get_locale_mutex());
+ _S_global->_M_add_reference();
+ _M_impl = _S_global;
+ }
}
locale