Mercurial > hg > vamp-build-and-test
comparison DEPENDENCIES/generic/include/boost/interprocess/sync/posix/recursive_mutex.hpp @ 101:c530137014c0
Update Boost headers (1.58.0)
author | Chris Cannam |
---|---|
date | Mon, 07 Sep 2015 11:12:49 +0100 |
parents | 2665513ce2d3 |
children |
comparison
equal
deleted
inserted
replaced
100:793467b5e61c | 101:c530137014c0 |
---|---|
25 ////////////////////////////////////////////////////////////////////////////// | 25 ////////////////////////////////////////////////////////////////////////////// |
26 | 26 |
27 #ifndef BOOST_INTERPROCESS_DETAIL_POSIX_RECURSIVE_MUTEX_HPP | 27 #ifndef BOOST_INTERPROCESS_DETAIL_POSIX_RECURSIVE_MUTEX_HPP |
28 #define BOOST_INTERPROCESS_DETAIL_POSIX_RECURSIVE_MUTEX_HPP | 28 #define BOOST_INTERPROCESS_DETAIL_POSIX_RECURSIVE_MUTEX_HPP |
29 | 29 |
30 #ifndef BOOST_CONFIG_HPP | |
31 # include <boost/config.hpp> | |
32 #endif | |
33 # | |
34 #if defined(BOOST_HAS_PRAGMA_ONCE) | |
35 # pragma once | |
36 #endif | |
37 | |
30 #include <boost/interprocess/detail/config_begin.hpp> | 38 #include <boost/interprocess/detail/config_begin.hpp> |
31 #include <boost/interprocess/detail/workaround.hpp> | 39 #include <boost/interprocess/detail/workaround.hpp> |
32 | 40 |
33 #include <pthread.h> | 41 #include <pthread.h> |
34 #include <errno.h> | 42 #include <errno.h> |
36 #include <boost/interprocess/sync/posix/ptime_to_timespec.hpp> | 44 #include <boost/interprocess/sync/posix/ptime_to_timespec.hpp> |
37 #include <boost/interprocess/detail/posix_time_types_wrk.hpp> | 45 #include <boost/interprocess/detail/posix_time_types_wrk.hpp> |
38 #include <boost/interprocess/exceptions.hpp> | 46 #include <boost/interprocess/exceptions.hpp> |
39 #ifndef BOOST_INTERPROCESS_POSIX_TIMEOUTS | 47 #ifndef BOOST_INTERPROCESS_POSIX_TIMEOUTS |
40 # include <boost/interprocess/detail/os_thread_functions.hpp> | 48 # include <boost/interprocess/detail/os_thread_functions.hpp> |
41 # include <boost/interprocess/sync/spin/wait.hpp> | 49 # include <boost/interprocess/sync/detail/common_algorithms.hpp> |
42 #endif | 50 #endif |
43 #include <boost/assert.hpp> | 51 #include <boost/assert.hpp> |
44 | 52 |
45 namespace boost { | 53 namespace boost { |
46 namespace interprocess { | 54 namespace interprocess { |
91 return res == 0; | 99 return res == 0; |
92 } | 100 } |
93 | 101 |
94 inline bool posix_recursive_mutex::timed_lock(const boost::posix_time::ptime &abs_time) | 102 inline bool posix_recursive_mutex::timed_lock(const boost::posix_time::ptime &abs_time) |
95 { | 103 { |
104 #ifdef BOOST_INTERPROCESS_POSIX_TIMEOUTS | |
105 //Posix does not support infinity absolute time so handle it here | |
96 if(abs_time == boost::posix_time::pos_infin){ | 106 if(abs_time == boost::posix_time::pos_infin){ |
97 this->lock(); | 107 this->lock(); |
98 return true; | 108 return true; |
99 } | 109 } |
100 #ifdef BOOST_INTERPROCESS_POSIX_TIMEOUTS | |
101 | 110 |
102 timespec ts = ptime_to_timespec(abs_time); | 111 timespec ts = ptime_to_timespec(abs_time); |
103 int res = pthread_mutex_timedlock(&m_mut, &ts); | 112 int res = pthread_mutex_timedlock(&m_mut, &ts); |
104 if (res != 0 && res != ETIMEDOUT) | 113 if (res != 0 && res != ETIMEDOUT) |
105 throw lock_exception(); | 114 throw lock_exception(); |
106 return res == 0; | 115 return res == 0; |
107 | 116 |
108 #else //BOOST_INTERPROCESS_POSIX_TIMEOUTS | 117 #else //BOOST_INTERPROCESS_POSIX_TIMEOUTS |
109 | 118 |
110 //Obtain current count and target time | 119 return ipcdetail::try_based_timed_lock(*this, abs_time); |
111 boost::posix_time::ptime now = microsec_clock::universal_time(); | |
112 spin_wait swait; | |
113 do{ | |
114 if(this->try_lock()){ | |
115 break; | |
116 } | |
117 now = microsec_clock::universal_time(); | |
118 | |
119 if(now >= abs_time){ | |
120 return false; | |
121 } | |
122 // relinquish current time slice | |
123 swait.yield(); | |
124 }while (true); | |
125 return true; | |
126 | 120 |
127 #endif //BOOST_INTERPROCESS_POSIX_TIMEOUTS | 121 #endif //BOOST_INTERPROCESS_POSIX_TIMEOUTS |
128 } | 122 } |
129 | 123 |
130 inline void posix_recursive_mutex::unlock() | 124 inline void posix_recursive_mutex::unlock() |