summaryrefslogtreecommitdiffstats
path: root/libstdc++-v3/include/std/shared_mutex
diff options
context:
space:
mode:
authorredi <redi@138bc75d-0d04-0410-961f-82ee72b054a4>2013-06-18 22:55:02 +0000
committerredi <redi@138bc75d-0d04-0410-961f-82ee72b054a4>2013-06-18 22:55:02 +0000
commit2851d736ebf1e8cceebb9106cab69d2c3fdc7624 (patch)
treec491d5047a720ef9b19dbe186747c2ab31667949 /libstdc++-v3/include/std/shared_mutex
parent3bc4161a6a4610c91897d637c64dfd50003455ba (diff)
downloadppe42-gcc-2851d736ebf1e8cceebb9106cab69d2c3fdc7624.tar.gz
ppe42-gcc-2851d736ebf1e8cceebb9106cab69d2c3fdc7624.zip
PR libstdc++/57641
* include/std/mutex (timed_mutex, recursive_timed_mutex): Move common functionality to new __timed_mutex_impl mixin. Overload try_lock_until to handle conversion between different clocks. Replace constrained __try_lock_for_impl overloads with conditional increment. * include/std/shared_mutex (shared_mutex::_Mutex): Use the new mixin. * testsuite/30_threads/timed_mutex/try_lock_until/57641.cc: New. git-svn-id: svn+ssh://gcc.gnu.org/svn/gcc/trunk@200180 138bc75d-0d04-0410-961f-82ee72b054a4
Diffstat (limited to 'libstdc++-v3/include/std/shared_mutex')
-rw-r--r--libstdc++-v3/include/std/shared_mutex48
1 files changed, 5 insertions, 43 deletions
diff --git a/libstdc++-v3/include/std/shared_mutex b/libstdc++-v3/include/std/shared_mutex
index 39ab83a2845..ff58825928e 100644
--- a/libstdc++-v3/include/std/shared_mutex
+++ b/libstdc++-v3/include/std/shared_mutex
@@ -56,55 +56,17 @@ _GLIBCXX_BEGIN_NAMESPACE_VERSION
class shared_mutex
{
#if _GTHREAD_USE_MUTEX_TIMEDLOCK
- struct _Mutex : mutex
+ struct _Mutex : mutex, __timed_mutex_impl<_Mutex>
{
- typedef chrono::steady_clock __clock_t;
-
- template <class _Rep, class _Period>
+ template<typename _Rep, typename _Period>
bool
try_lock_for(const chrono::duration<_Rep, _Period>& __rtime)
- { return __try_lock_for_impl(__rtime); }
+ { return _M_try_lock_for(__rtime); }
- template <class _Clock, class _Duration>
+ template<typename _Clock, typename _Duration>
bool
try_lock_until(const chrono::time_point<_Clock, _Duration>& __atime)
- {
- chrono::time_point<_Clock, chrono::seconds> __s =
- chrono::time_point_cast<chrono::seconds>(__atime);
-
- chrono::nanoseconds __ns =
- chrono::duration_cast<chrono::nanoseconds>(__atime - __s);
-
- __gthread_time_t __ts = {
- static_cast<std::time_t>(__s.time_since_epoch().count()),
- static_cast<long>(__ns.count())
- };
-
- return !__gthread_mutex_timedlock(native_handle(), &__ts);
- }
-
- private:
- template<typename _Rep, typename _Period>
- typename enable_if<
- ratio_less_equal<__clock_t::period, _Period>::value, bool>::type
- __try_lock_for_impl(const chrono::duration<_Rep, _Period>& __rtime)
- {
- __clock_t::time_point __atime = __clock_t::now()
- + chrono::duration_cast<__clock_t::duration>(__rtime);
-
- return try_lock_until(__atime);
- }
-
- template <typename _Rep, typename _Period>
- typename enable_if<
- !ratio_less_equal<__clock_t::period, _Period>::value, bool>::type
- __try_lock_for_impl(const chrono::duration<_Rep, _Period>& __rtime)
- {
- __clock_t::time_point __atime = __clock_t::now()
- + ++chrono::duration_cast<__clock_t::duration>(__rtime);
-
- return try_lock_until(__atime);
- }
+ { return _M_try_lock_until(__atime); }
};
#else
typedef mutex _Mutex;
OpenPOWER on IntegriCloud