Added boost header
This commit is contained in:
46
test/external/boost/interprocess/sync/emulation/interprocess_barrier.hpp
vendored
Normal file
46
test/external/boost/interprocess/sync/emulation/interprocess_barrier.hpp
vendored
Normal file
@@ -0,0 +1,46 @@
|
||||
//////////////////////////////////////////////////////////////////////////////
|
||||
//
|
||||
// (C) Copyright Ion Gaztanaga 2006. Distributed under the Boost
|
||||
// Software License, Version 1.0. (See accompanying file
|
||||
// LICENSE_1_0.txt or copy at http://www.boost.org/LICENSE_1_0.txt)
|
||||
//
|
||||
// See http://www.boost.org/libs/interprocess for documentation.
|
||||
//
|
||||
//////////////////////////////////////////////////////////////////////////////
|
||||
|
||||
#include<boost/interprocess/exceptions.hpp>
|
||||
#include <boost/interprocess/detail/posix_time_types_wrk.hpp>
|
||||
#include <boost/interprocess/sync/scoped_lock.hpp>
|
||||
|
||||
namespace boost {
|
||||
namespace interprocess {
|
||||
|
||||
inline barrier::barrier(unsigned int count)
|
||||
: m_threshold(count), m_count(count), m_generation(0)
|
||||
{
|
||||
if (count == 0)
|
||||
throw std::invalid_argument("count cannot be zero.");
|
||||
}
|
||||
|
||||
inline barrier::~barrier(){}
|
||||
|
||||
inline bool barrier::wait()
|
||||
{
|
||||
scoped_lock<interprocess_mutex> lock(m_mutex);
|
||||
unsigned int gen = m_generation;
|
||||
|
||||
if (--m_count == 0){
|
||||
m_generation++;
|
||||
m_count = m_threshold;
|
||||
m_cond.notify_all();
|
||||
return true;
|
||||
}
|
||||
|
||||
while (gen == m_generation){
|
||||
m_cond.wait(lock);
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
} //namespace interprocess {
|
||||
} //namespace boost {
|
||||
200
test/external/boost/interprocess/sync/emulation/interprocess_condition.hpp
vendored
Normal file
200
test/external/boost/interprocess/sync/emulation/interprocess_condition.hpp
vendored
Normal file
@@ -0,0 +1,200 @@
|
||||
//////////////////////////////////////////////////////////////////////////////
|
||||
//
|
||||
// (C) Copyright Ion Gaztanaga 2005-2009. Distributed under the Boost
|
||||
// Software License, Version 1.0. (See accompanying file
|
||||
// LICENSE_1_0.txt or copy at http://www.boost.org/LICENSE_1_0.txt)
|
||||
//
|
||||
// See http://www.boost.org/libs/interprocess for documentation.
|
||||
//
|
||||
//////////////////////////////////////////////////////////////////////////////
|
||||
|
||||
#include <boost/interprocess/detail/posix_time_types_wrk.hpp>
|
||||
#include <boost/interprocess/detail/move.hpp>
|
||||
namespace boost {
|
||||
namespace interprocess {
|
||||
|
||||
inline interprocess_condition::interprocess_condition()
|
||||
{
|
||||
//Note that this class is initialized to zero.
|
||||
//So zeroed memory can be interpreted as an initialized
|
||||
//condition variable
|
||||
m_command = SLEEP;
|
||||
m_num_waiters = 0;
|
||||
}
|
||||
|
||||
inline interprocess_condition::~interprocess_condition()
|
||||
{
|
||||
//Trivial destructor
|
||||
}
|
||||
|
||||
inline void interprocess_condition::notify_one()
|
||||
{
|
||||
this->notify(NOTIFY_ONE);
|
||||
}
|
||||
|
||||
inline void interprocess_condition::notify_all()
|
||||
{
|
||||
this->notify(NOTIFY_ALL);
|
||||
}
|
||||
|
||||
inline void interprocess_condition::notify(boost::uint32_t command)
|
||||
{
|
||||
//This interprocess_mutex guarantees that no other thread can enter to the
|
||||
//do_timed_wait method logic, so that thread count will be
|
||||
//constant until the function writes a NOTIFY_ALL command.
|
||||
//It also guarantees that no other notification can be signaled
|
||||
//on this interprocess_condition before this one ends
|
||||
m_enter_mut.lock();
|
||||
|
||||
//Return if there are no waiters
|
||||
if(!ipcdetail::atomic_read32(&m_num_waiters)) {
|
||||
m_enter_mut.unlock();
|
||||
return;
|
||||
}
|
||||
|
||||
//Notify that all threads should execute wait logic
|
||||
while(SLEEP != ipcdetail::atomic_cas32(const_cast<boost::uint32_t*>(&m_command), command, SLEEP)){
|
||||
ipcdetail::thread_yield();
|
||||
}
|
||||
/*
|
||||
//Wait until the threads are woken
|
||||
while(SLEEP != ipcdetail::atomic_cas32(const_cast<boost::uint32_t*>(&m_command), 0)){
|
||||
ipcdetail::thread_yield();
|
||||
}
|
||||
*/
|
||||
//The enter interprocess_mutex will rest locked until the last waiting thread unlocks it
|
||||
}
|
||||
|
||||
inline void interprocess_condition::do_wait(interprocess_mutex &mut)
|
||||
{
|
||||
this->do_timed_wait(false, boost::posix_time::ptime(), mut);
|
||||
}
|
||||
|
||||
inline bool interprocess_condition::do_timed_wait
|
||||
(const boost::posix_time::ptime &abs_time, interprocess_mutex &mut)
|
||||
{
|
||||
return this->do_timed_wait(true, abs_time, mut);
|
||||
}
|
||||
|
||||
inline bool interprocess_condition::do_timed_wait(bool tout_enabled,
|
||||
const boost::posix_time::ptime &abs_time,
|
||||
interprocess_mutex &mut)
|
||||
{
|
||||
boost::posix_time::ptime now = microsec_clock::universal_time();
|
||||
|
||||
if(tout_enabled){
|
||||
if(now >= abs_time) return false;
|
||||
}
|
||||
|
||||
typedef boost::interprocess::scoped_lock<interprocess_mutex> InternalLock;
|
||||
//The enter interprocess_mutex guarantees that while executing a notification,
|
||||
//no other thread can execute the do_timed_wait method.
|
||||
{
|
||||
//---------------------------------------------------------------
|
||||
InternalLock lock;
|
||||
if(tout_enabled){
|
||||
InternalLock dummy(m_enter_mut, abs_time);
|
||||
lock = boost::interprocess::move(dummy);
|
||||
}
|
||||
else{
|
||||
InternalLock dummy(m_enter_mut);
|
||||
lock = boost::interprocess::move(dummy);
|
||||
}
|
||||
|
||||
if(!lock)
|
||||
return false;
|
||||
//---------------------------------------------------------------
|
||||
//We increment the waiting thread count protected so that it will be
|
||||
//always constant when another thread enters the notification logic.
|
||||
//The increment marks this thread as "waiting on interprocess_condition"
|
||||
ipcdetail::atomic_inc32(const_cast<boost::uint32_t*>(&m_num_waiters));
|
||||
|
||||
//We unlock the external interprocess_mutex atomically with the increment
|
||||
mut.unlock();
|
||||
}
|
||||
|
||||
//By default, we suppose that no timeout has happened
|
||||
bool timed_out = false, unlock_enter_mut= false;
|
||||
|
||||
//Loop until a notification indicates that the thread should
|
||||
//exit or timeout occurs
|
||||
while(1){
|
||||
//The thread sleeps/spins until a interprocess_condition commands a notification
|
||||
//Notification occurred, we will lock the checking interprocess_mutex so that
|
||||
while(ipcdetail::atomic_read32(&m_command) == SLEEP){
|
||||
ipcdetail::thread_yield();
|
||||
|
||||
//Check for timeout
|
||||
if(tout_enabled){
|
||||
now = microsec_clock::universal_time();
|
||||
|
||||
if(now >= abs_time){
|
||||
//If we can lock the interprocess_mutex it means that no notification
|
||||
//is being executed in this interprocess_condition variable
|
||||
timed_out = m_enter_mut.try_lock();
|
||||
|
||||
//If locking fails, indicates that another thread is executing
|
||||
//notification, so we play the notification game
|
||||
if(!timed_out){
|
||||
//There is an ongoing notification, we will try again later
|
||||
continue;
|
||||
}
|
||||
//No notification in execution, since enter interprocess_mutex is locked.
|
||||
//We will execute time-out logic, so we will decrement count,
|
||||
//release the enter interprocess_mutex and return false.
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
//If a timeout occurred, the interprocess_mutex will not execute checking logic
|
||||
if(tout_enabled && timed_out){
|
||||
//Decrement wait count
|
||||
ipcdetail::atomic_dec32(const_cast<boost::uint32_t*>(&m_num_waiters));
|
||||
unlock_enter_mut = true;
|
||||
break;
|
||||
}
|
||||
else{
|
||||
boost::uint32_t result = ipcdetail::atomic_cas32
|
||||
(const_cast<boost::uint32_t*>(&m_command), SLEEP, NOTIFY_ONE);
|
||||
if(result == SLEEP){
|
||||
//Other thread has been notified and since it was a NOTIFY one
|
||||
//command, this thread must sleep again
|
||||
continue;
|
||||
}
|
||||
else if(result == NOTIFY_ONE){
|
||||
//If it was a NOTIFY_ONE command, only this thread should
|
||||
//exit. This thread has atomically marked command as sleep before
|
||||
//so no other thread will exit.
|
||||
//Decrement wait count.
|
||||
unlock_enter_mut = true;
|
||||
ipcdetail::atomic_dec32(const_cast<boost::uint32_t*>(&m_num_waiters));
|
||||
break;
|
||||
}
|
||||
else{
|
||||
//If it is a NOTIFY_ALL command, all threads should return
|
||||
//from do_timed_wait function. Decrement wait count.
|
||||
unlock_enter_mut = 1 == ipcdetail::atomic_dec32(const_cast<boost::uint32_t*>(&m_num_waiters));
|
||||
//Check if this is the last thread of notify_all waiters
|
||||
//Only the last thread will release the interprocess_mutex
|
||||
if(unlock_enter_mut){
|
||||
ipcdetail::atomic_cas32(const_cast<boost::uint32_t*>(&m_command), SLEEP, NOTIFY_ALL);
|
||||
}
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
//Unlock the enter interprocess_mutex if it is a single notification, if this is
|
||||
//the last notified thread in a notify_all or a timeout has occurred
|
||||
if(unlock_enter_mut){
|
||||
m_enter_mut.unlock();
|
||||
}
|
||||
|
||||
//Lock external again before returning from the method
|
||||
mut.lock();
|
||||
return !timed_out;
|
||||
}
|
||||
|
||||
} //namespace interprocess
|
||||
} // namespace boost
|
||||
75
test/external/boost/interprocess/sync/emulation/interprocess_semaphore.hpp
vendored
Normal file
75
test/external/boost/interprocess/sync/emulation/interprocess_semaphore.hpp
vendored
Normal file
@@ -0,0 +1,75 @@
|
||||
//////////////////////////////////////////////////////////////////////////////
|
||||
//
|
||||
// (C) Copyright Ion Gaztanaga 2005-2009. Distributed under the Boost
|
||||
// Software License, Version 1.0. (See accompanying file
|
||||
// LICENSE_1_0.txt or copy at http://www.boost.org/LICENSE_1_0.txt)
|
||||
//
|
||||
// See http://www.boost.org/libs/interprocess for documentation.
|
||||
//
|
||||
//////////////////////////////////////////////////////////////////////////////
|
||||
|
||||
#include<boost/interprocess/exceptions.hpp>
|
||||
#include <boost/interprocess/detail/posix_time_types_wrk.hpp>
|
||||
|
||||
namespace boost {
|
||||
namespace interprocess {
|
||||
|
||||
|
||||
inline interprocess_semaphore::~interprocess_semaphore()
|
||||
{}
|
||||
|
||||
inline interprocess_semaphore::interprocess_semaphore(unsigned int initialCount)
|
||||
{ ipcdetail::atomic_write32(&this->m_count, boost::uint32_t(initialCount)); }
|
||||
|
||||
inline void interprocess_semaphore::post()
|
||||
{
|
||||
ipcdetail::atomic_inc32(&m_count);
|
||||
}
|
||||
|
||||
inline void interprocess_semaphore::wait()
|
||||
{
|
||||
while(!ipcdetail::atomic_add_unless32(&m_count, boost::uint32_t(-1), boost::uint32_t(0))){
|
||||
while(ipcdetail::atomic_read32(&m_count) == 0){
|
||||
ipcdetail::thread_yield();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
inline bool interprocess_semaphore::try_wait()
|
||||
{
|
||||
return ipcdetail::atomic_add_unless32(&m_count, boost::uint32_t(-1), boost::uint32_t(0));
|
||||
}
|
||||
|
||||
inline bool interprocess_semaphore::timed_wait(const boost::posix_time::ptime &abs_time)
|
||||
{
|
||||
if(abs_time == boost::posix_time::pos_infin){
|
||||
this->wait();
|
||||
return true;
|
||||
}
|
||||
//Obtain current count and target time
|
||||
boost::posix_time::ptime now(microsec_clock::universal_time());
|
||||
if(now >= abs_time)
|
||||
return false;
|
||||
|
||||
do{
|
||||
if(this->try_wait()){
|
||||
break;
|
||||
}
|
||||
now = microsec_clock::universal_time();
|
||||
|
||||
if(now >= abs_time){
|
||||
return this->try_wait();
|
||||
}
|
||||
// relinquish current time slice
|
||||
ipcdetail::thread_yield();
|
||||
}while (true);
|
||||
return true;
|
||||
}
|
||||
/*
|
||||
inline int interprocess_semaphore::get_count() const
|
||||
{
|
||||
return (int)ipcdetail::atomic_read32(&m_count);
|
||||
}*/
|
||||
|
||||
} //namespace interprocess {
|
||||
} //namespace boost {
|
||||
116
test/external/boost/interprocess/sync/emulation/mutex.hpp
vendored
Normal file
116
test/external/boost/interprocess/sync/emulation/mutex.hpp
vendored
Normal file
@@ -0,0 +1,116 @@
|
||||
//////////////////////////////////////////////////////////////////////////////
|
||||
//
|
||||
// (C) Copyright Ion Gaztanaga 2005-2009. Distributed under the Boost
|
||||
// Software License, Version 1.0. (See accompanying file
|
||||
// LICENSE_1_0.txt or copy at http://www.boost.org/LICENSE_1_0.txt)
|
||||
//
|
||||
// See http://www.boost.org/libs/interprocess for documentation.
|
||||
//
|
||||
//////////////////////////////////////////////////////////////////////////////
|
||||
|
||||
#ifndef BOOST_INTERPROCESS_DETAIL_EMULATION_MUTEX_HPP
|
||||
#define BOOST_INTERPROCESS_DETAIL_EMULATION_MUTEX_HPP
|
||||
|
||||
#if (defined _MSC_VER) && (_MSC_VER >= 1200)
|
||||
# pragma once
|
||||
#endif
|
||||
|
||||
#include <boost/interprocess/detail/config_begin.hpp>
|
||||
#include <boost/interprocess/detail/workaround.hpp>
|
||||
#include <boost/interprocess/detail/posix_time_types_wrk.hpp>
|
||||
#include <boost/assert.hpp>
|
||||
#include <boost/interprocess/detail/atomic.hpp>
|
||||
#include <boost/cstdint.hpp>
|
||||
#include <boost/interprocess/detail/os_thread_functions.hpp>
|
||||
|
||||
namespace boost {
|
||||
namespace interprocess {
|
||||
namespace ipcdetail {
|
||||
|
||||
class emulation_mutex
|
||||
{
|
||||
emulation_mutex(const emulation_mutex &);
|
||||
emulation_mutex &operator=(const emulation_mutex &);
|
||||
public:
|
||||
|
||||
emulation_mutex();
|
||||
~emulation_mutex();
|
||||
|
||||
void lock();
|
||||
bool try_lock();
|
||||
bool timed_lock(const boost::posix_time::ptime &abs_time);
|
||||
void unlock();
|
||||
void take_ownership(){};
|
||||
private:
|
||||
volatile boost::uint32_t m_s;
|
||||
};
|
||||
|
||||
inline emulation_mutex::emulation_mutex()
|
||||
: m_s(0)
|
||||
{
|
||||
//Note that this class is initialized to zero.
|
||||
//So zeroed memory can be interpreted as an
|
||||
//initialized mutex
|
||||
}
|
||||
|
||||
inline emulation_mutex::~emulation_mutex()
|
||||
{
|
||||
//Trivial destructor
|
||||
}
|
||||
|
||||
inline void emulation_mutex::lock(void)
|
||||
{
|
||||
do{
|
||||
boost::uint32_t prev_s = ipcdetail::atomic_cas32(const_cast<boost::uint32_t*>(&m_s), 1, 0);
|
||||
|
||||
if (m_s == 1 && prev_s == 0){
|
||||
break;
|
||||
}
|
||||
// relinquish current timeslice
|
||||
ipcdetail::thread_yield();
|
||||
}while (true);
|
||||
}
|
||||
|
||||
inline bool emulation_mutex::try_lock(void)
|
||||
{
|
||||
boost::uint32_t prev_s = ipcdetail::atomic_cas32(const_cast<boost::uint32_t*>(&m_s), 1, 0);
|
||||
return m_s == 1 && prev_s == 0;
|
||||
}
|
||||
|
||||
inline bool emulation_mutex::timed_lock(const boost::posix_time::ptime &abs_time)
|
||||
{
|
||||
if(abs_time == boost::posix_time::pos_infin){
|
||||
this->lock();
|
||||
return true;
|
||||
}
|
||||
//Obtain current count and target time
|
||||
boost::posix_time::ptime now = microsec_clock::universal_time();
|
||||
|
||||
if(now >= abs_time) return false;
|
||||
|
||||
do{
|
||||
if(this->try_lock()){
|
||||
break;
|
||||
}
|
||||
now = microsec_clock::universal_time();
|
||||
|
||||
if(now >= abs_time){
|
||||
return false;
|
||||
}
|
||||
// relinquish current time slice
|
||||
ipcdetail::thread_yield();
|
||||
}while (true);
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
inline void emulation_mutex::unlock(void)
|
||||
{ ipcdetail::atomic_cas32(const_cast<boost::uint32_t*>(&m_s), 0, 1); }
|
||||
|
||||
} //namespace ipcdetail {
|
||||
} //namespace interprocess {
|
||||
} //namespace boost {
|
||||
|
||||
#include <boost/interprocess/detail/config_end.hpp>
|
||||
|
||||
#endif //BOOST_INTERPROCESS_DETAIL_EMULATION_MUTEX_HPP
|
||||
68
test/external/boost/interprocess/sync/emulation/named_creation_functor.hpp
vendored
Normal file
68
test/external/boost/interprocess/sync/emulation/named_creation_functor.hpp
vendored
Normal file
@@ -0,0 +1,68 @@
|
||||
//////////////////////////////////////////////////////////////////////////////
|
||||
//
|
||||
// (C) Copyright Ion Gaztanaga 2007-2009. Distributed under the Boost
|
||||
// Software License, Version 1.0. (See accompanying file
|
||||
// LICENSE_1_0.txt or copy at http://www.boost.org/LICENSE_1_0.txt)
|
||||
//
|
||||
// See http://www.boost.org/libs/interprocess for documentation.
|
||||
//
|
||||
//////////////////////////////////////////////////////////////////////////////
|
||||
|
||||
#ifndef BOOST_INTERPROCESS_SYNC_NAMED_CREATION_FUNCTOR_HPP
|
||||
#define BOOST_INTERPROCESS_SYNC_NAMED_CREATION_FUNCTOR_HPP
|
||||
|
||||
#include <boost/interprocess/creation_tags.hpp>
|
||||
#include <boost/interprocess/detail/type_traits.hpp>
|
||||
#include <boost/interprocess/detail/mpl.hpp>
|
||||
|
||||
namespace boost {
|
||||
namespace interprocess {
|
||||
namespace ipcdetail {
|
||||
|
||||
struct named_creation_functor_no_arg{};
|
||||
|
||||
template <class T, class Arg = named_creation_functor_no_arg>
|
||||
class named_creation_functor
|
||||
{
|
||||
typedef named_creation_functor_no_arg no_arg_t;
|
||||
public:
|
||||
named_creation_functor(ipcdetail::create_enum_t type, Arg arg = Arg())
|
||||
: m_creation_type(type), m_arg(arg){}
|
||||
|
||||
template<class ArgType>
|
||||
void construct(void *address, typename enable_if_c<is_same<ArgType, no_arg_t>::value>::type * = 0) const
|
||||
{ new(address)T; }
|
||||
|
||||
template<class ArgType>
|
||||
void construct(void *address, typename enable_if_c<!is_same<ArgType, no_arg_t>::value>::type * = 0) const
|
||||
{ new(address)T(m_arg); }
|
||||
|
||||
bool operator()(void *address, std::size_t, bool created) const
|
||||
{
|
||||
switch(m_creation_type){
|
||||
case ipcdetail::DoOpen:
|
||||
return true;
|
||||
break;
|
||||
case ipcdetail::DoCreate:
|
||||
case ipcdetail::DoOpenOrCreate:
|
||||
if(created){
|
||||
construct<Arg>(address);
|
||||
}
|
||||
return true;
|
||||
break;
|
||||
|
||||
default:
|
||||
return false;
|
||||
break;
|
||||
}
|
||||
}
|
||||
private:
|
||||
ipcdetail::create_enum_t m_creation_type;
|
||||
Arg m_arg;
|
||||
};
|
||||
|
||||
} //namespace ipcdetail {
|
||||
} //namespace interprocess {
|
||||
} //namespace boost {
|
||||
|
||||
#endif //BOOST_INTERPROCESS_SYNC_NAMED_CREATION_FUNCTOR_HPP
|
||||
167
test/external/boost/interprocess/sync/emulation/recursive_mutex.hpp
vendored
Normal file
167
test/external/boost/interprocess/sync/emulation/recursive_mutex.hpp
vendored
Normal file
@@ -0,0 +1,167 @@
|
||||
//////////////////////////////////////////////////////////////////////////////
|
||||
//
|
||||
// (C) Copyright Ion Gaztanaga 2005-2009. Distributed under the Boost
|
||||
// Software License, Version 1.0. (See accompanying file
|
||||
// LICENSE_1_0.txt or copy at http://www.boost.org/LICENSE_1_0.txt)
|
||||
//
|
||||
// See http://www.boost.org/libs/interprocess for documentation.
|
||||
//
|
||||
//////////////////////////////////////////////////////////////////////////////
|
||||
//
|
||||
// Parts of the pthread code come from Boost Threads code:
|
||||
//
|
||||
//////////////////////////////////////////////////////////////////////////////
|
||||
//
|
||||
// Copyright (C) 2001-2003
|
||||
// William E. Kempf
|
||||
//
|
||||
// Permission to use, copy, modify, distribute and sell this software
|
||||
// and its documentation for any purpose is hereby granted without fee,
|
||||
// provided that the above copyright notice appear in all copies and
|
||||
// that both that copyright notice and this permission notice appear
|
||||
// in supporting documentation. William E. Kempf makes no representations
|
||||
// about the suitability of this software for any purpose.
|
||||
// It is provided "as is" without express or implied warranty.
|
||||
//////////////////////////////////////////////////////////////////////////////
|
||||
|
||||
#ifndef BOOST_INTERPROCESS_DETAIL_EMULATION_RECURSIVE_MUTEX_HPP
|
||||
#define BOOST_INTERPROCESS_DETAIL_EMULATION_RECURSIVE_MUTEX_HPP
|
||||
|
||||
#include <boost/interprocess/detail/posix_time_types_wrk.hpp>
|
||||
#include <boost/interprocess/detail/os_thread_functions.hpp>
|
||||
#include <boost/interprocess/exceptions.hpp>
|
||||
#include <boost/interprocess/detail/atomic.hpp>
|
||||
#include <boost/cstdint.hpp>
|
||||
#include <boost/interprocess/detail/os_thread_functions.hpp>
|
||||
#include <boost/interprocess/sync/emulation/mutex.hpp>
|
||||
#include <boost/assert.hpp>
|
||||
|
||||
namespace boost {
|
||||
namespace interprocess {
|
||||
namespace ipcdetail {
|
||||
|
||||
class emulation_recursive_mutex
|
||||
{
|
||||
emulation_recursive_mutex(const emulation_recursive_mutex &);
|
||||
emulation_recursive_mutex &operator=(const emulation_recursive_mutex &);
|
||||
public:
|
||||
|
||||
emulation_recursive_mutex();
|
||||
~emulation_recursive_mutex();
|
||||
|
||||
void lock();
|
||||
bool try_lock();
|
||||
bool timed_lock(const boost::posix_time::ptime &abs_time);
|
||||
void unlock();
|
||||
void take_ownership();
|
||||
private:
|
||||
emulation_mutex m_mutex;
|
||||
unsigned int m_nLockCount;
|
||||
volatile ipcdetail::OS_systemwide_thread_id_t m_nOwner;
|
||||
volatile boost::uint32_t m_s;
|
||||
};
|
||||
|
||||
inline emulation_recursive_mutex::emulation_recursive_mutex()
|
||||
: m_nLockCount(0), m_nOwner(ipcdetail::get_invalid_systemwide_thread_id()){}
|
||||
|
||||
inline emulation_recursive_mutex::~emulation_recursive_mutex(){}
|
||||
|
||||
inline void emulation_recursive_mutex::lock()
|
||||
{
|
||||
typedef ipcdetail::OS_systemwide_thread_id_t handle_t;
|
||||
const handle_t thr_id(ipcdetail::get_current_systemwide_thread_id());
|
||||
handle_t old_id;
|
||||
ipcdetail::systemwide_thread_id_copy(m_nOwner, old_id);
|
||||
if(ipcdetail::equal_systemwide_thread_id(thr_id , old_id)){
|
||||
if((unsigned int)(m_nLockCount+1) == 0){
|
||||
//Overflow, throw an exception
|
||||
throw interprocess_exception("boost::interprocess::emulation_recursive_mutex recursive lock overflow");
|
||||
}
|
||||
++m_nLockCount;
|
||||
}
|
||||
else{
|
||||
m_mutex.lock();
|
||||
ipcdetail::systemwide_thread_id_copy(thr_id, m_nOwner);
|
||||
m_nLockCount = 1;
|
||||
}
|
||||
}
|
||||
|
||||
inline bool emulation_recursive_mutex::try_lock()
|
||||
{
|
||||
typedef ipcdetail::OS_systemwide_thread_id_t handle_t;
|
||||
handle_t thr_id(ipcdetail::get_current_systemwide_thread_id());
|
||||
handle_t old_id;
|
||||
ipcdetail::systemwide_thread_id_copy(m_nOwner, old_id);
|
||||
if(ipcdetail::equal_systemwide_thread_id(thr_id , old_id)) { // we own it
|
||||
if((unsigned int)(m_nLockCount+1) == 0){
|
||||
//Overflow, throw an exception
|
||||
throw interprocess_exception("boost::interprocess::emulation_recursive_mutex recursive lock overflow");
|
||||
}
|
||||
++m_nLockCount;
|
||||
return true;
|
||||
}
|
||||
if(m_mutex.try_lock()){
|
||||
ipcdetail::systemwide_thread_id_copy(thr_id, m_nOwner);
|
||||
m_nLockCount = 1;
|
||||
return true;
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
inline bool emulation_recursive_mutex::timed_lock(const boost::posix_time::ptime &abs_time)
|
||||
{
|
||||
typedef ipcdetail::OS_systemwide_thread_id_t handle_t;
|
||||
if(abs_time == boost::posix_time::pos_infin){
|
||||
this->lock();
|
||||
return true;
|
||||
}
|
||||
const handle_t thr_id(ipcdetail::get_current_systemwide_thread_id());
|
||||
handle_t old_id;
|
||||
ipcdetail::systemwide_thread_id_copy(m_nOwner, old_id);
|
||||
if(ipcdetail::equal_systemwide_thread_id(thr_id , old_id)) { // we own it
|
||||
if((unsigned int)(m_nLockCount+1) == 0){
|
||||
//Overflow, throw an exception
|
||||
throw interprocess_exception("boost::interprocess::emulation_recursive_mutex recursive lock overflow");
|
||||
}
|
||||
++m_nLockCount;
|
||||
return true;
|
||||
}
|
||||
if(m_mutex.timed_lock(abs_time)){
|
||||
ipcdetail::systemwide_thread_id_copy(thr_id, m_nOwner);
|
||||
m_nLockCount = 1;
|
||||
return true;
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
inline void emulation_recursive_mutex::unlock()
|
||||
{
|
||||
typedef ipcdetail::OS_systemwide_thread_id_t handle_t;
|
||||
handle_t old_id;
|
||||
ipcdetail::systemwide_thread_id_copy(m_nOwner, old_id);
|
||||
const handle_t thr_id(ipcdetail::get_current_systemwide_thread_id());
|
||||
(void)old_id;
|
||||
(void)thr_id;
|
||||
BOOST_ASSERT(ipcdetail::equal_systemwide_thread_id(thr_id, old_id));
|
||||
--m_nLockCount;
|
||||
if(!m_nLockCount){
|
||||
const handle_t new_id(ipcdetail::get_invalid_systemwide_thread_id());
|
||||
ipcdetail::systemwide_thread_id_copy(new_id, m_nOwner);
|
||||
m_mutex.unlock();
|
||||
}
|
||||
}
|
||||
|
||||
inline void emulation_recursive_mutex::take_ownership()
|
||||
{
|
||||
typedef ipcdetail::OS_systemwide_thread_id_t handle_t;
|
||||
this->m_nLockCount = 1;
|
||||
const handle_t thr_id(ipcdetail::get_current_systemwide_thread_id());
|
||||
ipcdetail::systemwide_thread_id_copy
|
||||
(thr_id, m_nOwner);
|
||||
}
|
||||
|
||||
} //namespace ipcdetail {
|
||||
} //namespace interprocess {
|
||||
} //namespace boost {
|
||||
|
||||
#endif //BOOST_INTERPROCESS_DETAIL_EMULATION_RECURSIVE_MUTEX_HPP
|
||||
Reference in New Issue
Block a user