updated boost on windows
This commit is contained in:
@@ -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
|
||||
|
||||
@@ -112,25 +112,25 @@ class shm_named_condition_any
|
||||
//!If there is a thread waiting on *this, change that
|
||||
//!thread's state to ready. Otherwise there is no effect.*/
|
||||
void notify_one()
|
||||
{ m_cond.notify_one(); }
|
||||
{ this->internal_cond().notify_one(); }
|
||||
|
||||
//!Change the state of all threads waiting on *this to ready.
|
||||
//!If there are no waiting threads, notify_all() has no effect.
|
||||
void notify_all()
|
||||
{ m_cond.notify_all(); }
|
||||
{ this->internal_cond().notify_all(); }
|
||||
|
||||
//!Releases the lock on the named_mutex object associated with lock, blocks
|
||||
//!the current thread of execution until readied by a call to
|
||||
//!this->notify_one() or this->notify_all(), and then reacquires the lock.
|
||||
template <typename L>
|
||||
void wait(L& lock)
|
||||
{ m_cond.wait(lock); }
|
||||
{ this->internal_cond().wait(lock); }
|
||||
|
||||
//!The same as:
|
||||
//!while (!pred()) wait(lock)
|
||||
template <typename L, typename Pr>
|
||||
void wait(L& lock, Pr pred)
|
||||
{ m_cond.wait(lock, pred); }
|
||||
{ this->internal_cond().wait(lock, pred); }
|
||||
|
||||
//!Releases the lock on the named_mutex object associated with lock, blocks
|
||||
//!the current thread of execution until readied by a call to
|
||||
@@ -139,14 +139,14 @@ class shm_named_condition_any
|
||||
//!Returns: false if time abs_time is reached, otherwise true.
|
||||
template <typename L>
|
||||
bool timed_wait(L& lock, const boost::posix_time::ptime &abs_time)
|
||||
{ return m_cond.timed_wait(lock, abs_time); }
|
||||
{ return this->internal_cond().timed_wait(lock, abs_time); }
|
||||
|
||||
//!The same as: while (!pred()) {
|
||||
//! if (!timed_wait(lock, abs_time)) return pred();
|
||||
//! } return true;
|
||||
template <typename L, typename Pr>
|
||||
bool timed_wait(L& lock, const boost::posix_time::ptime &abs_time, Pr pred)
|
||||
{ return m_cond.timed_wait(lock, abs_time, pred); }
|
||||
{ return this->internal_cond().timed_wait(lock, abs_time, pred); }
|
||||
|
||||
//!Erases a named condition from the system.
|
||||
//!Returns false on error. Never throws.
|
||||
@@ -172,7 +172,8 @@ class shm_named_condition_any
|
||||
|
||||
typedef ipcdetail::condition_any_wrapper<internal_condition_members> internal_condition;
|
||||
|
||||
internal_condition m_cond;
|
||||
internal_condition &internal_cond()
|
||||
{ return *static_cast<internal_condition*>(m_shmem.get_user_address()); }
|
||||
|
||||
friend class boost::interprocess::ipcdetail::interprocess_tester;
|
||||
void dont_close_on_destruction()
|
||||
|
||||
@@ -45,7 +45,7 @@ class spin_mutex
|
||||
bool try_lock();
|
||||
bool timed_lock(const boost::posix_time::ptime &abs_time);
|
||||
void unlock();
|
||||
void take_ownership(){};
|
||||
void take_ownership(){}
|
||||
private:
|
||||
volatile boost::uint32_t m_s;
|
||||
};
|
||||
@@ -64,7 +64,21 @@ inline spin_mutex::~spin_mutex()
|
||||
}
|
||||
|
||||
inline void spin_mutex::lock(void)
|
||||
{ return ipcdetail::try_based_lock(*this); }
|
||||
{
|
||||
#ifdef BOOST_INTERPROCESS_ENABLE_TIMEOUT_WHEN_LOCKING
|
||||
boost::posix_time::ptime wait_time
|
||||
= microsec_clock::universal_time()
|
||||
+ boost::posix_time::milliseconds(BOOST_INTERPROCESS_TIMEOUT_WHEN_LOCKING_DURATION_MS);
|
||||
if (!timed_lock(wait_time))
|
||||
{
|
||||
throw interprocess_exception(timeout_when_locking_error
|
||||
, "Interprocess mutex timeout when locking. Possible deadlock: "
|
||||
"owner died without unlocking?");
|
||||
}
|
||||
#else
|
||||
return ipcdetail::try_based_lock(*this);
|
||||
#endif
|
||||
}
|
||||
|
||||
inline bool spin_mutex::try_lock(void)
|
||||
{
|
||||
|
||||
@@ -31,57 +31,42 @@ namespace boost {
|
||||
namespace interprocess {
|
||||
namespace ipcdetail {
|
||||
|
||||
inline bool winapi_wrapper_timed_wait_for_single_object(void *handle, const boost::posix_time::ptime &abs_time);
|
||||
|
||||
inline void winapi_wrapper_wait_for_single_object(void *handle)
|
||||
{
|
||||
unsigned long ret = winapi::wait_for_single_object(handle, winapi::infinite_time);
|
||||
if(ret != winapi::wait_object_0){
|
||||
if(ret != winapi::wait_abandoned){
|
||||
error_info err = system_error_code();
|
||||
throw interprocess_exception(err);
|
||||
}
|
||||
else{ //Special case for orphaned mutexes
|
||||
winapi::release_mutex(handle);
|
||||
throw interprocess_exception(owner_dead_error);
|
||||
}
|
||||
}
|
||||
winapi_wrapper_timed_wait_for_single_object(handle, boost::posix_time::pos_infin);
|
||||
}
|
||||
|
||||
inline bool winapi_wrapper_try_wait_for_single_object(void *handle)
|
||||
{
|
||||
unsigned long ret = winapi::wait_for_single_object(handle, 0);
|
||||
if(ret == winapi::wait_object_0){
|
||||
return true;
|
||||
}
|
||||
else if(ret == winapi::wait_timeout){
|
||||
return false;
|
||||
}
|
||||
else{
|
||||
error_info err = system_error_code();
|
||||
throw interprocess_exception(err);
|
||||
}
|
||||
return winapi_wrapper_timed_wait_for_single_object(handle, boost::posix_time::min_date_time);
|
||||
}
|
||||
|
||||
inline bool winapi_wrapper_timed_wait_for_single_object(void *handle, const boost::posix_time::ptime &abs_time)
|
||||
{
|
||||
//Windows does not support infinity abs_time so check it
|
||||
if(abs_time == boost::posix_time::pos_infin){
|
||||
winapi_wrapper_wait_for_single_object(handle);
|
||||
return true;
|
||||
}
|
||||
const boost::posix_time::ptime cur_time = microsec_clock::universal_time();
|
||||
//Windows uses relative wait times so check for negative waits
|
||||
//and implement as 0 wait to allow try-semantics as POSIX mandates.
|
||||
unsigned long ret = winapi::wait_for_single_object
|
||||
( handle
|
||||
, (abs_time <= cur_time) ? 0u
|
||||
: (abs_time - cur_time).total_milliseconds()
|
||||
);
|
||||
unsigned long time = 0u;
|
||||
if (abs_time == boost::posix_time::pos_infin){
|
||||
time = winapi::infinite_time;
|
||||
}
|
||||
else if(abs_time > cur_time){
|
||||
time = (abs_time - cur_time).total_milliseconds();
|
||||
}
|
||||
|
||||
unsigned long ret = winapi::wait_for_single_object(handle, time);
|
||||
if(ret == winapi::wait_object_0){
|
||||
return true;
|
||||
}
|
||||
else if(ret == winapi::wait_timeout){
|
||||
return false;
|
||||
}
|
||||
else if(ret == winapi::wait_abandoned){ //Special case for orphaned mutexes
|
||||
winapi::release_mutex(handle);
|
||||
throw interprocess_exception(owner_dead_error);
|
||||
}
|
||||
else{
|
||||
error_info err = system_error_code();
|
||||
throw interprocess_exception(err);
|
||||
@@ -94,4 +79,4 @@ inline bool winapi_wrapper_timed_wait_for_single_object(void *handle, const boos
|
||||
|
||||
#include <boost/interprocess/detail/config_end.hpp>
|
||||
|
||||
#endif //BOOST_INTERPROCESS_DETAIL_WINAPI_MUTEX_WRAPPER_HPP
|
||||
#endif //BOOST_INTERPROCESS_DETAIL_WINAPI_WRAPPER_COMMON_HPP
|
||||
|
||||
Reference in New Issue
Block a user