summaryrefslogtreecommitdiff
path: root/boost/thread/win32/basic_recursive_mutex.hpp
diff options
context:
space:
mode:
Diffstat (limited to 'boost/thread/win32/basic_recursive_mutex.hpp')
-rw-r--r--boost/thread/win32/basic_recursive_mutex.hpp42
1 files changed, 41 insertions, 1 deletions
diff --git a/boost/thread/win32/basic_recursive_mutex.hpp b/boost/thread/win32/basic_recursive_mutex.hpp
index e748aa725c..eb5ec8489d 100644
--- a/boost/thread/win32/basic_recursive_mutex.hpp
+++ b/boost/thread/win32/basic_recursive_mutex.hpp
@@ -4,6 +4,7 @@
// basic_recursive_mutex.hpp
//
// (C) Copyright 2006-8 Anthony Williams
+// (C) Copyright 2011-2012 Vicente J. Botet Escriba
//
// Distributed under the Boost Software License, Version 1.0. (See
// accompanying file LICENSE_1_0.txt or copy at
@@ -11,6 +12,10 @@
#include <boost/thread/win32/thread_primitives.hpp>
#include <boost/thread/win32/basic_timed_mutex.hpp>
+#ifdef BOOST_THREAD_USES_CHRONO
+#include <boost/chrono/system_clocks.hpp>
+#include <boost/chrono/ceil.hpp>
+#endif
#include <boost/config/abi_prefix.hpp>
@@ -64,6 +69,20 @@ namespace boost
return timed_lock(get_system_time()+timeout);
}
+#ifdef BOOST_THREAD_USES_CHRONO
+ template <class Rep, class Period>
+ bool try_lock_for(const chrono::duration<Rep, Period>& rel_time)
+ {
+ long const current_thread_id=win32::GetCurrentThreadId();
+ return try_recursive_lock(current_thread_id) || try_timed_lock_for(current_thread_id,rel_time);
+ }
+ template <class Clock, class Duration>
+ bool try_lock_until(const chrono::time_point<Clock, Duration>& t)
+ {
+ long const current_thread_id=win32::GetCurrentThreadId();
+ return try_recursive_lock(current_thread_id) || try_timed_lock_until(current_thread_id,t);
+ }
+#endif
void unlock()
{
if(!--recursion_count)
@@ -105,7 +124,28 @@ namespace boost
}
return false;
}
-
+ template <typename TP>
+ bool try_timed_lock_until(long current_thread_id,TP const& target)
+ {
+ if(mutex.try_lock_until(target))
+ {
+ BOOST_INTERLOCKED_EXCHANGE(&locking_thread_id,current_thread_id);
+ recursion_count=1;
+ return true;
+ }
+ return false;
+ }
+ template <typename D>
+ bool try_timed_lock_for(long current_thread_id,D const& target)
+ {
+ if(mutex.try_lock_for(target))
+ {
+ BOOST_INTERLOCKED_EXCHANGE(&locking_thread_id,current_thread_id);
+ recursion_count=1;
+ return true;
+ }
+ return false;
+ }
};
typedef basic_recursive_mutex_impl<basic_timed_mutex> basic_recursive_mutex;