Mercurial > hg > vamp-build-and-test
comparison DEPENDENCIES/generic/include/boost/interprocess/sync/posix/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_MUTEX_HPP | 27 #ifndef BOOST_INTERPROCESS_DETAIL_POSIX_MUTEX_HPP |
28 #define BOOST_INTERPROCESS_DETAIL_POSIX_MUTEX_HPP | 28 #define BOOST_INTERPROCESS_DETAIL_POSIX_MUTEX_HPP |
29 | 29 |
30 #if (defined _MSC_VER) && (_MSC_VER >= 1200) | 30 #ifndef BOOST_CONFIG_HPP |
31 # include <boost/config.hpp> | |
32 #endif | |
33 # | |
34 #if defined(BOOST_HAS_PRAGMA_ONCE) | |
31 # pragma once | 35 # pragma once |
32 #endif | 36 #endif |
33 | 37 |
34 #include <boost/interprocess/detail/config_begin.hpp> | 38 #include <boost/interprocess/detail/config_begin.hpp> |
35 #include <boost/interprocess/detail/workaround.hpp> | 39 #include <boost/interprocess/detail/workaround.hpp> |
42 #include <boost/interprocess/exceptions.hpp> | 46 #include <boost/interprocess/exceptions.hpp> |
43 #include <boost/interprocess/sync/posix/pthread_helpers.hpp> | 47 #include <boost/interprocess/sync/posix/pthread_helpers.hpp> |
44 | 48 |
45 #ifndef BOOST_INTERPROCESS_POSIX_TIMEOUTS | 49 #ifndef BOOST_INTERPROCESS_POSIX_TIMEOUTS |
46 # include <boost/interprocess/detail/os_thread_functions.hpp> | 50 # include <boost/interprocess/detail/os_thread_functions.hpp> |
47 # include <boost/interprocess/sync/spin/wait.hpp> | 51 # include <boost/interprocess/sync/detail/common_algorithms.hpp> |
48 #endif | 52 #endif |
49 #include <boost/assert.hpp> | 53 #include <boost/assert.hpp> |
50 | 54 |
51 namespace boost { | 55 namespace boost { |
52 namespace interprocess { | 56 namespace interprocess { |
101 return res == 0; | 105 return res == 0; |
102 } | 106 } |
103 | 107 |
104 inline bool posix_mutex::timed_lock(const boost::posix_time::ptime &abs_time) | 108 inline bool posix_mutex::timed_lock(const boost::posix_time::ptime &abs_time) |
105 { | 109 { |
110 #ifdef BOOST_INTERPROCESS_POSIX_TIMEOUTS | |
111 //Posix does not support infinity absolute time so handle it here | |
106 if(abs_time == boost::posix_time::pos_infin){ | 112 if(abs_time == boost::posix_time::pos_infin){ |
107 this->lock(); | 113 this->lock(); |
108 return true; | 114 return true; |
109 } | 115 } |
110 #ifdef BOOST_INTERPROCESS_POSIX_TIMEOUTS | |
111 | |
112 timespec ts = ptime_to_timespec(abs_time); | 116 timespec ts = ptime_to_timespec(abs_time); |
113 int res = pthread_mutex_timedlock(&m_mut, &ts); | 117 int res = pthread_mutex_timedlock(&m_mut, &ts); |
114 if (res != 0 && res != ETIMEDOUT) | 118 if (res != 0 && res != ETIMEDOUT) |
115 throw lock_exception(); | 119 throw lock_exception(); |
116 return res == 0; | 120 return res == 0; |
117 | 121 |
118 #else //BOOST_INTERPROCESS_POSIX_TIMEOUTS | 122 #else //BOOST_INTERPROCESS_POSIX_TIMEOUTS |
119 | 123 |
120 //Obtain current count and target time | 124 return ipcdetail::try_based_timed_lock(*this, abs_time); |
121 boost::posix_time::ptime now = microsec_clock::universal_time(); | |
122 | |
123 spin_wait swait; | |
124 do{ | |
125 if(this->try_lock()){ | |
126 break; | |
127 } | |
128 now = microsec_clock::universal_time(); | |
129 | |
130 if(now >= abs_time){ | |
131 return false; | |
132 } | |
133 // relinquish current time slice | |
134 swait.yield(); | |
135 }while (true); | |
136 return true; | |
137 | 125 |
138 #endif //BOOST_INTERPROCESS_POSIX_TIMEOUTS | 126 #endif //BOOST_INTERPROCESS_POSIX_TIMEOUTS |
139 } | 127 } |
140 | 128 |
141 inline void posix_mutex::unlock() | 129 inline void posix_mutex::unlock() |