summaryrefslogtreecommitdiff
path: root/boost/interprocess/sync/detail/common_algorithms.hpp
diff options
context:
space:
mode:
Diffstat (limited to 'boost/interprocess/sync/detail/common_algorithms.hpp')
-rw-r--r--boost/interprocess/sync/detail/common_algorithms.hpp43
1 files changed, 43 insertions, 0 deletions
diff --git a/boost/interprocess/sync/detail/common_algorithms.hpp b/boost/interprocess/sync/detail/common_algorithms.hpp
index 1a72d686b4..87739b8121 100644
--- a/boost/interprocess/sync/detail/common_algorithms.hpp
+++ b/boost/interprocess/sync/detail/common_algorithms.hpp
@@ -72,6 +72,49 @@ void try_based_lock(MutexType &m)
}
}
+template<class MutexType>
+void timed_based_lock(MutexType &m, unsigned const uCheckPeriodSec)
+{
+ const boost::posix_time::time_duration dur(0, 0, uCheckPeriodSec);
+ boost::posix_time::ptime deadline(microsec_clock::universal_time()+dur);
+ if(!m.timed_lock(deadline)){
+ spin_wait swait;
+ do{
+ deadline = microsec_clock::universal_time()+dur;
+ if(m.timed_lock(deadline)){
+ break;
+ }
+ else{
+ swait.yield();
+ }
+ }
+ while(1);
+ }
+}
+
+template<class MutexType>
+void timed_based_timed_lock(MutexType &m, const boost::posix_time::ptime &abs_time, unsigned const uCheckPeriodSec)
+{
+ const boost::posix_time::time_duration dur(0, 0, uCheckPeriodSec);
+ boost::posix_time::ptime deadline(microsec_clock::universal_time()+dur);
+ if(abs_time <= deadline){
+ m.timed_lock(abs_time);
+ }
+ else if(!m.timed_lock(deadline)){
+ spin_wait swait;
+ do{
+ deadline = microsec_clock::universal_time()+dur;
+ if(m.timed_lock(deadline)){
+ break;
+ }
+ else{
+ swait.yield();
+ }
+ }
+ while(1);
+ }
+}
+
} //namespace ipcdetail
} //namespace interprocess
} //namespace boost