mirror of
https://github.com/boostorg/thread.git
synced 2026-02-09 11:32:12 +00:00
Compare commits
3 Commits
fix/blocki
...
svn-branch
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
03ef4775b9 | ||
|
|
1f16717aa0 | ||
|
|
1a0c11f4cd |
@@ -1,24 +0,0 @@
|
|||||||
// 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.
|
|
||||||
|
|
||||||
#if !defined(BOOST_THREAD_WEK01082003_HPP)
|
|
||||||
#define BOOST_THREAD_WEK01082003_HPP
|
|
||||||
|
|
||||||
#include <boost/thread/thread.hpp>
|
|
||||||
#include <boost/thread/condition.hpp>
|
|
||||||
#include <boost/thread/exceptions.hpp>
|
|
||||||
#include <boost/thread/mutex.hpp>
|
|
||||||
#include <boost/thread/once.hpp>
|
|
||||||
#include <boost/thread/recursive_mutex.hpp>
|
|
||||||
#include <boost/thread/tss.hpp>
|
|
||||||
#include <boost/thread/xtime.hpp>
|
|
||||||
|
|
||||||
#endif
|
|
||||||
@@ -1,40 +0,0 @@
|
|||||||
// Copyright (C) 2002-2003
|
|
||||||
// David Moore, 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_BARRIER_JDM030602_HPP
|
|
||||||
#define BOOST_BARRIER_JDM030602_HPP
|
|
||||||
|
|
||||||
#include <boost/thread/detail/config.hpp>
|
|
||||||
|
|
||||||
#include <boost/thread/mutex.hpp>
|
|
||||||
#include <boost/thread/condition.hpp>
|
|
||||||
|
|
||||||
namespace boost {
|
|
||||||
|
|
||||||
class BOOST_THREAD_DECL barrier
|
|
||||||
{
|
|
||||||
public:
|
|
||||||
barrier(unsigned int count);
|
|
||||||
~barrier();
|
|
||||||
|
|
||||||
bool wait();
|
|
||||||
|
|
||||||
private:
|
|
||||||
mutex m_mutex;
|
|
||||||
condition m_cond;
|
|
||||||
unsigned int m_threshold;
|
|
||||||
unsigned int m_count;
|
|
||||||
unsigned int m_generation;
|
|
||||||
};
|
|
||||||
|
|
||||||
} // namespace boost
|
|
||||||
|
|
||||||
#endif
|
|
||||||
@@ -1,198 +0,0 @@
|
|||||||
// 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_CONDITION_WEK070601_HPP
|
|
||||||
#define BOOST_CONDITION_WEK070601_HPP
|
|
||||||
|
|
||||||
#include <boost/thread/detail/config.hpp>
|
|
||||||
|
|
||||||
#include <boost/thread/exceptions.hpp>
|
|
||||||
#include <boost/utility.hpp>
|
|
||||||
#include <boost/thread/detail/lock.hpp>
|
|
||||||
|
|
||||||
#if defined(BOOST_HAS_PTHREADS)
|
|
||||||
# include <pthread.h>
|
|
||||||
#elif defined(BOOST_HAS_MPTASKS)
|
|
||||||
# include "scoped_critical_region.hpp"
|
|
||||||
#endif
|
|
||||||
|
|
||||||
namespace boost {
|
|
||||||
|
|
||||||
struct xtime;
|
|
||||||
|
|
||||||
namespace detail {
|
|
||||||
|
|
||||||
class BOOST_THREAD_DECL condition_impl : private noncopyable
|
|
||||||
{
|
|
||||||
friend class condition;
|
|
||||||
|
|
||||||
public:
|
|
||||||
condition_impl();
|
|
||||||
~condition_impl();
|
|
||||||
|
|
||||||
void notify_one();
|
|
||||||
void notify_all();
|
|
||||||
|
|
||||||
#if (defined(BOOST_HAS_WINTHREADS) || defined(BOOST_HAS_MPTASKS))
|
|
||||||
void enter_wait();
|
|
||||||
void do_wait();
|
|
||||||
bool do_timed_wait(const xtime& xt);
|
|
||||||
#elif defined(BOOST_HAS_PTHREADS)
|
|
||||||
void do_wait(pthread_mutex_t* pmutex);
|
|
||||||
bool do_timed_wait(const xtime& xt, pthread_mutex_t* pmutex);
|
|
||||||
#endif
|
|
||||||
|
|
||||||
#if defined(BOOST_HAS_WINTHREADS)
|
|
||||||
void* m_gate;
|
|
||||||
void* m_queue;
|
|
||||||
void* m_mutex;
|
|
||||||
unsigned m_gone; // # threads that timed out and never made it to m_queue
|
|
||||||
unsigned long m_blocked; // # threads blocked on the condition
|
|
||||||
unsigned m_waiting; // # threads no longer waiting for the condition but
|
|
||||||
// still waiting to be removed from m_queue
|
|
||||||
#elif defined(BOOST_HAS_PTHREADS)
|
|
||||||
pthread_cond_t m_condition;
|
|
||||||
#elif defined(BOOST_HAS_MPTASKS)
|
|
||||||
MPSemaphoreID m_gate;
|
|
||||||
MPSemaphoreID m_queue;
|
|
||||||
threads::mac::detail::scoped_critical_region m_mutex;
|
|
||||||
threads::mac::detail::scoped_critical_region m_mutex_mutex;
|
|
||||||
unsigned m_gone; // # threads that timed out and never made it to m_queue
|
|
||||||
unsigned long m_blocked; // # threads blocked on the condition
|
|
||||||
unsigned m_waiting; // # threads no longer waiting for the condition but
|
|
||||||
// still waiting to be removed from m_queue
|
|
||||||
#endif
|
|
||||||
};
|
|
||||||
|
|
||||||
} // namespace detail
|
|
||||||
|
|
||||||
class condition : private noncopyable
|
|
||||||
{
|
|
||||||
public:
|
|
||||||
condition() { }
|
|
||||||
~condition() { }
|
|
||||||
|
|
||||||
void notify_one() { m_impl.notify_one(); }
|
|
||||||
void notify_all() { m_impl.notify_all(); }
|
|
||||||
|
|
||||||
template <typename L>
|
|
||||||
void wait(L& lock)
|
|
||||||
{
|
|
||||||
if (!lock)
|
|
||||||
throw lock_error();
|
|
||||||
|
|
||||||
do_wait(lock.m_mutex);
|
|
||||||
}
|
|
||||||
|
|
||||||
template <typename L, typename Pr>
|
|
||||||
void wait(L& lock, Pr pred)
|
|
||||||
{
|
|
||||||
if (!lock)
|
|
||||||
throw lock_error();
|
|
||||||
|
|
||||||
while (!pred())
|
|
||||||
do_wait(lock.m_mutex);
|
|
||||||
}
|
|
||||||
|
|
||||||
template <typename L>
|
|
||||||
bool timed_wait(L& lock, const xtime& xt)
|
|
||||||
{
|
|
||||||
if (!lock)
|
|
||||||
throw lock_error();
|
|
||||||
|
|
||||||
return do_timed_wait(lock.m_mutex, xt);
|
|
||||||
}
|
|
||||||
|
|
||||||
template <typename L, typename Pr>
|
|
||||||
bool timed_wait(L& lock, const xtime& xt, Pr pred)
|
|
||||||
{
|
|
||||||
if (!lock)
|
|
||||||
throw lock_error();
|
|
||||||
|
|
||||||
while (!pred())
|
|
||||||
{
|
|
||||||
if (!do_timed_wait(lock.m_mutex, xt))
|
|
||||||
return false;
|
|
||||||
}
|
|
||||||
|
|
||||||
return true;
|
|
||||||
}
|
|
||||||
|
|
||||||
private:
|
|
||||||
detail::condition_impl m_impl;
|
|
||||||
|
|
||||||
template <typename M>
|
|
||||||
void do_wait(M& mutex)
|
|
||||||
{
|
|
||||||
#if (defined(BOOST_HAS_WINTHREADS) || defined(BOOST_HAS_MPTASKS))
|
|
||||||
m_impl.enter_wait();
|
|
||||||
#endif
|
|
||||||
|
|
||||||
typedef detail::thread::lock_ops<M>
|
|
||||||
#if defined(__HP_aCC) && __HP_aCC <= 33900 && !defined(BOOST_STRICT_CONFIG)
|
|
||||||
# define lock_ops lock_ops_ // HP confuses lock_ops witht the template
|
|
||||||
#endif
|
|
||||||
lock_ops;
|
|
||||||
|
|
||||||
typename lock_ops::lock_state state;
|
|
||||||
lock_ops::unlock(mutex, state);
|
|
||||||
|
|
||||||
#if defined(BOOST_HAS_PTHREADS)
|
|
||||||
m_impl.do_wait(state.pmutex);
|
|
||||||
#elif (defined(BOOST_HAS_WINTHREADS) || defined(BOOST_HAS_MPTASKS))
|
|
||||||
m_impl.do_wait();
|
|
||||||
#endif
|
|
||||||
|
|
||||||
lock_ops::lock(mutex, state);
|
|
||||||
#undef lock_ops
|
|
||||||
}
|
|
||||||
|
|
||||||
template <typename M>
|
|
||||||
bool do_timed_wait(M& mutex, const xtime& xt)
|
|
||||||
{
|
|
||||||
#if (defined(BOOST_HAS_WINTHREADS) || defined(BOOST_HAS_MPTASKS))
|
|
||||||
m_impl.enter_wait();
|
|
||||||
#endif
|
|
||||||
|
|
||||||
typedef detail::thread::lock_ops<M>
|
|
||||||
#if defined(__HP_aCC) && __HP_aCC <= 33900 && !defined(BOOST_STRICT_CONFIG)
|
|
||||||
# define lock_ops lock_ops_ // HP confuses lock_ops witht the template
|
|
||||||
#endif
|
|
||||||
lock_ops;
|
|
||||||
|
|
||||||
typename lock_ops::lock_state state;
|
|
||||||
lock_ops::unlock(mutex, state);
|
|
||||||
|
|
||||||
bool ret = false;
|
|
||||||
|
|
||||||
#if defined(BOOST_HAS_PTHREADS)
|
|
||||||
ret = m_impl.do_timed_wait(xt, state.pmutex);
|
|
||||||
#elif (defined(BOOST_HAS_WINTHREADS) || defined(BOOST_HAS_MPTASKS))
|
|
||||||
ret = m_impl.do_timed_wait(xt);
|
|
||||||
#endif
|
|
||||||
|
|
||||||
lock_ops::lock(mutex, state);
|
|
||||||
#undef lock_ops
|
|
||||||
|
|
||||||
return ret;
|
|
||||||
}
|
|
||||||
};
|
|
||||||
|
|
||||||
} // namespace boost
|
|
||||||
|
|
||||||
// Change Log:
|
|
||||||
// 8 Feb 01 WEKEMPF Initial version.
|
|
||||||
// 22 May 01 WEKEMPF Modified to use xtime for time outs.
|
|
||||||
// 23 May 01 WEKEMPF Removed "duration" timed_waits, as they are too
|
|
||||||
// difficult to use with spurious wakeups.
|
|
||||||
// 3 Jan 03 WEKEMPF Modified for DLL implementation.
|
|
||||||
|
|
||||||
#endif // BOOST_CONDITION_WEK070601_HPP
|
|
||||||
@@ -1,84 +0,0 @@
|
|||||||
// 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_THREAD_CONFIG_WEK01032003_HPP
|
|
||||||
#define BOOST_THREAD_CONFIG_WEK01032003_HPP
|
|
||||||
|
|
||||||
#include <boost/config.hpp>
|
|
||||||
|
|
||||||
// insist on threading support being available:
|
|
||||||
#include <boost/config/requires_threads.hpp>
|
|
||||||
|
|
||||||
#if defined(BOOST_HAS_WINTHREADS)
|
|
||||||
# if defined(BOOST_THREAD_BUILD_DLL) //Build dll
|
|
||||||
# define BOOST_THREAD_DECL __declspec(dllexport)
|
|
||||||
# elif defined(BOOST_THREAD_BUILD_LIB) //Build lib
|
|
||||||
# define BOOST_THREAD_DECL
|
|
||||||
# elif defined(BOOST_THREAD_USE_DLL) //Use dll
|
|
||||||
# define BOOST_THREAD_DECL __declspec(dllimport)
|
|
||||||
# define BOOST_DYN_LINK
|
|
||||||
# elif defined(BOOST_THREAD_USE_LIB) //Use lib
|
|
||||||
# define BOOST_THREAD_DECL
|
|
||||||
# else //Use default
|
|
||||||
# if defined(BOOST_MSVC) || defined(BOOST_INTEL_WIN)
|
|
||||||
//For VC++, choose according to threading library setting
|
|
||||||
# if defined(_DLL)
|
|
||||||
//Threading library is dll: use Boost.Threads dll
|
|
||||||
# define BOOST_THREAD_USE_DLL
|
|
||||||
# define BOOST_THREAD_DECL __declspec(dllimport)
|
|
||||||
# define BOOST_DYN_LINK
|
|
||||||
# else
|
|
||||||
//Threading library is lib: used Boost.Threads lib
|
|
||||||
# define BOOST_THREAD_USE_LIB
|
|
||||||
# define BOOST_THREAD_DECL
|
|
||||||
# endif
|
|
||||||
# else
|
|
||||||
//For compilers not yet supporting auto-tss cleanup
|
|
||||||
//with Boost.Threads lib, use Boost.Threads dll
|
|
||||||
# define BOOST_THREAD_USE_DLL
|
|
||||||
# define BOOST_THREAD_DECL __declspec(dllimport)
|
|
||||||
# define BOOST_DYN_LINK
|
|
||||||
# endif
|
|
||||||
# endif
|
|
||||||
#else
|
|
||||||
# define BOOST_THREAD_DECL
|
|
||||||
# if defined(BOOST_THREAD_USE_LIB) //Use dll
|
|
||||||
# define BOOST_THREAD_USE_DLL
|
|
||||||
# define BOOST_DYN_LINK
|
|
||||||
# elif defined(BOOST_THREAD_USE_DLL) //Use lib
|
|
||||||
# define BOOST_THREAD_USE_LIB
|
|
||||||
# else //Use default
|
|
||||||
# define BOOST_THREAD_USE_LIB
|
|
||||||
# endif
|
|
||||||
#endif // BOOST_HAS_WINTHREADS
|
|
||||||
|
|
||||||
//
|
|
||||||
// Automatically link to the correct build variant where possible.
|
|
||||||
//
|
|
||||||
#if !defined(BOOST_ALL_NO_LIB) && !defined(BOOST_THREAD_NO_LIB) && !defined(BOOST_THREAD_BUILD_DLL) && !defined(BOOST_THREAD_BUILD_LIB)
|
|
||||||
//
|
|
||||||
// Set the name of our library, this will get undef'ed by auto_link.hpp
|
|
||||||
// once it's done with it:
|
|
||||||
//
|
|
||||||
#if defined(BOOST_THREAD_LIB_NAME)
|
|
||||||
# define BOOST_LIB_NAME BOOST_THREAD_LIB_NAME
|
|
||||||
#else
|
|
||||||
# define BOOST_LIB_NAME boost_thread
|
|
||||||
#endif
|
|
||||||
//
|
|
||||||
// If we're importing code from a dll, then tell auto_link.hpp about it:
|
|
||||||
//
|
|
||||||
// And include the header that does the work:
|
|
||||||
//
|
|
||||||
#include <boost/config/auto_link.hpp>
|
|
||||||
#endif // auto-linking disabled
|
|
||||||
|
|
||||||
#endif // BOOST_THREAD_CONFIG_WEK1032003_HPP
|
|
||||||
@@ -1,39 +0,0 @@
|
|||||||
// Copyright (C) 2001-2003
|
|
||||||
// Mac Murrett
|
|
||||||
//
|
|
||||||
// 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 for most recent version including documentation.
|
|
||||||
|
|
||||||
#ifndef BOOST_FORCE_CAST_MJM012402_HPP
|
|
||||||
#define BOOST_FORCE_CAST_MJM012402_HPP
|
|
||||||
|
|
||||||
#include <boost/thread/detail/config.hpp>
|
|
||||||
|
|
||||||
namespace boost {
|
|
||||||
namespace detail {
|
|
||||||
namespace thread {
|
|
||||||
|
|
||||||
// force_cast will convert anything to anything.
|
|
||||||
|
|
||||||
// general case
|
|
||||||
template<class Return_Type, class Argument_Type>
|
|
||||||
inline Return_Type &force_cast(Argument_Type &rSrc)
|
|
||||||
{
|
|
||||||
return(*reinterpret_cast<Return_Type *>(&rSrc));
|
|
||||||
}
|
|
||||||
|
|
||||||
// specialization for const
|
|
||||||
template<class Return_Type, class Argument_Type>
|
|
||||||
inline const Return_Type &force_cast(const Argument_Type &rSrc)
|
|
||||||
{
|
|
||||||
return(*reinterpret_cast<const Return_Type *>(&rSrc));
|
|
||||||
}
|
|
||||||
|
|
||||||
} // namespace thread
|
|
||||||
} // namespace detail
|
|
||||||
} // namespace boost
|
|
||||||
|
|
||||||
#endif // BOOST_FORCE_CAST_MJM012402_HPP
|
|
||||||
@@ -1,214 +0,0 @@
|
|||||||
// 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_XLOCK_WEK070601_HPP
|
|
||||||
#define BOOST_XLOCK_WEK070601_HPP
|
|
||||||
|
|
||||||
#include <boost/thread/detail/config.hpp>
|
|
||||||
|
|
||||||
#include <boost/utility.hpp>
|
|
||||||
#include <boost/thread/exceptions.hpp>
|
|
||||||
|
|
||||||
namespace boost {
|
|
||||||
|
|
||||||
class condition;
|
|
||||||
struct xtime;
|
|
||||||
|
|
||||||
namespace detail { namespace thread {
|
|
||||||
|
|
||||||
template <typename Mutex>
|
|
||||||
class lock_ops : private noncopyable
|
|
||||||
{
|
|
||||||
private:
|
|
||||||
lock_ops() { }
|
|
||||||
|
|
||||||
public:
|
|
||||||
typedef typename Mutex::cv_state lock_state;
|
|
||||||
|
|
||||||
static void lock(Mutex& m)
|
|
||||||
{
|
|
||||||
m.do_lock();
|
|
||||||
}
|
|
||||||
static bool trylock(Mutex& m)
|
|
||||||
{
|
|
||||||
return m.do_trylock();
|
|
||||||
}
|
|
||||||
static bool timedlock(Mutex& m, const xtime& xt)
|
|
||||||
{
|
|
||||||
return m.do_timedlock(xt);
|
|
||||||
}
|
|
||||||
static void unlock(Mutex& m)
|
|
||||||
{
|
|
||||||
m.do_unlock();
|
|
||||||
}
|
|
||||||
static void lock(Mutex& m, lock_state& state)
|
|
||||||
{
|
|
||||||
m.do_lock(state);
|
|
||||||
}
|
|
||||||
static void unlock(Mutex& m, lock_state& state)
|
|
||||||
{
|
|
||||||
m.do_unlock(state);
|
|
||||||
}
|
|
||||||
};
|
|
||||||
|
|
||||||
template <typename Mutex>
|
|
||||||
class scoped_lock : private noncopyable
|
|
||||||
{
|
|
||||||
public:
|
|
||||||
typedef Mutex mutex_type;
|
|
||||||
|
|
||||||
explicit scoped_lock(Mutex& mx, bool initially_locked=true)
|
|
||||||
: m_mutex(mx), m_locked(false)
|
|
||||||
{
|
|
||||||
if (initially_locked) lock();
|
|
||||||
}
|
|
||||||
~scoped_lock()
|
|
||||||
{
|
|
||||||
if (m_locked) unlock();
|
|
||||||
}
|
|
||||||
|
|
||||||
void lock()
|
|
||||||
{
|
|
||||||
if (m_locked) throw lock_error();
|
|
||||||
lock_ops<Mutex>::lock(m_mutex);
|
|
||||||
m_locked = true;
|
|
||||||
}
|
|
||||||
void unlock()
|
|
||||||
{
|
|
||||||
if (!m_locked) throw lock_error();
|
|
||||||
lock_ops<Mutex>::unlock(m_mutex);
|
|
||||||
m_locked = false;
|
|
||||||
}
|
|
||||||
|
|
||||||
bool locked() const { return m_locked; }
|
|
||||||
operator const void*() const { return m_locked ? this : 0; }
|
|
||||||
|
|
||||||
private:
|
|
||||||
friend class boost::condition;
|
|
||||||
|
|
||||||
Mutex& m_mutex;
|
|
||||||
bool m_locked;
|
|
||||||
};
|
|
||||||
|
|
||||||
template <typename TryMutex>
|
|
||||||
class scoped_try_lock : private noncopyable
|
|
||||||
{
|
|
||||||
public:
|
|
||||||
typedef TryMutex mutex_type;
|
|
||||||
|
|
||||||
explicit scoped_try_lock(TryMutex& mx)
|
|
||||||
: m_mutex(mx), m_locked(false)
|
|
||||||
{
|
|
||||||
try_lock();
|
|
||||||
}
|
|
||||||
scoped_try_lock(TryMutex& mx, bool initially_locked)
|
|
||||||
: m_mutex(mx), m_locked(false)
|
|
||||||
{
|
|
||||||
if (initially_locked) lock();
|
|
||||||
}
|
|
||||||
~scoped_try_lock()
|
|
||||||
{
|
|
||||||
if (m_locked) unlock();
|
|
||||||
}
|
|
||||||
|
|
||||||
void lock()
|
|
||||||
{
|
|
||||||
if (m_locked) throw lock_error();
|
|
||||||
lock_ops<TryMutex>::lock(m_mutex);
|
|
||||||
m_locked = true;
|
|
||||||
}
|
|
||||||
bool try_lock()
|
|
||||||
{
|
|
||||||
if (m_locked) throw lock_error();
|
|
||||||
return (m_locked = lock_ops<TryMutex>::trylock(m_mutex));
|
|
||||||
}
|
|
||||||
void unlock()
|
|
||||||
{
|
|
||||||
if (!m_locked) throw lock_error();
|
|
||||||
lock_ops<TryMutex>::unlock(m_mutex);
|
|
||||||
m_locked = false;
|
|
||||||
}
|
|
||||||
|
|
||||||
bool locked() const { return m_locked; }
|
|
||||||
operator const void*() const { return m_locked ? this : 0; }
|
|
||||||
|
|
||||||
private:
|
|
||||||
friend class boost::condition;
|
|
||||||
|
|
||||||
TryMutex& m_mutex;
|
|
||||||
bool m_locked;
|
|
||||||
};
|
|
||||||
|
|
||||||
template <typename TimedMutex>
|
|
||||||
class scoped_timed_lock : private noncopyable
|
|
||||||
{
|
|
||||||
public:
|
|
||||||
typedef TimedMutex mutex_type;
|
|
||||||
|
|
||||||
scoped_timed_lock(TimedMutex& mx, const xtime& xt)
|
|
||||||
: m_mutex(mx), m_locked(false)
|
|
||||||
{
|
|
||||||
timed_lock(xt);
|
|
||||||
}
|
|
||||||
scoped_timed_lock(TimedMutex& mx, bool initially_locked)
|
|
||||||
: m_mutex(mx), m_locked(false)
|
|
||||||
{
|
|
||||||
if (initially_locked) lock();
|
|
||||||
}
|
|
||||||
~scoped_timed_lock()
|
|
||||||
{
|
|
||||||
if (m_locked) unlock();
|
|
||||||
}
|
|
||||||
|
|
||||||
void lock()
|
|
||||||
{
|
|
||||||
if (m_locked) throw lock_error();
|
|
||||||
lock_ops<TimedMutex>::lock(m_mutex);
|
|
||||||
m_locked = true;
|
|
||||||
}
|
|
||||||
bool try_lock()
|
|
||||||
{
|
|
||||||
if (m_locked) throw lock_error();
|
|
||||||
return (m_locked = lock_ops<TimedMutex>::trylock(m_mutex));
|
|
||||||
}
|
|
||||||
bool timed_lock(const xtime& xt)
|
|
||||||
{
|
|
||||||
if (m_locked) throw lock_error();
|
|
||||||
return (m_locked = lock_ops<TimedMutex>::timedlock(m_mutex, xt));
|
|
||||||
}
|
|
||||||
void unlock()
|
|
||||||
{
|
|
||||||
if (!m_locked) throw lock_error();
|
|
||||||
lock_ops<TimedMutex>::unlock(m_mutex);
|
|
||||||
m_locked = false;
|
|
||||||
}
|
|
||||||
|
|
||||||
bool locked() const { return m_locked; }
|
|
||||||
operator const void*() const { return m_locked ? this : 0; }
|
|
||||||
|
|
||||||
private:
|
|
||||||
friend class boost::condition;
|
|
||||||
|
|
||||||
TimedMutex& m_mutex;
|
|
||||||
bool m_locked;
|
|
||||||
};
|
|
||||||
|
|
||||||
} // namespace thread
|
|
||||||
} // namespace detail
|
|
||||||
} // namespace boost
|
|
||||||
|
|
||||||
#endif // BOOST_XLOCK_WEK070601_HPP
|
|
||||||
|
|
||||||
// Change Log:
|
|
||||||
// 8 Feb 01 WEKEMPF Initial version.
|
|
||||||
// 22 May 01 WEKEMPF Modified to use xtime for time outs.
|
|
||||||
// 30 Jul 01 WEKEMPF Moved lock types into boost::detail::thread. Renamed
|
|
||||||
// some types. Added locked() methods.
|
|
||||||
File diff suppressed because it is too large
Load Diff
@@ -1,59 +0,0 @@
|
|||||||
// Copyright (C) 2001-2003
|
|
||||||
// Mac Murrett
|
|
||||||
//
|
|
||||||
// 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 for most recent version including documentation.
|
|
||||||
|
|
||||||
#ifndef BOOST_SINGLETON_MJM012402_HPP
|
|
||||||
#define BOOST_SINGLETON_MJM012402_HPP
|
|
||||||
|
|
||||||
#include <boost/thread/detail/config.hpp>
|
|
||||||
|
|
||||||
namespace boost {
|
|
||||||
namespace detail {
|
|
||||||
namespace thread {
|
|
||||||
|
|
||||||
// class singleton has the same goal as all singletons: create one instance of
|
|
||||||
// a class on demand, then dish it out as requested.
|
|
||||||
|
|
||||||
template <class T>
|
|
||||||
class singleton : private T
|
|
||||||
{
|
|
||||||
private:
|
|
||||||
singleton();
|
|
||||||
~singleton();
|
|
||||||
|
|
||||||
public:
|
|
||||||
static T &instance();
|
|
||||||
};
|
|
||||||
|
|
||||||
|
|
||||||
template <class T>
|
|
||||||
inline singleton<T>::singleton()
|
|
||||||
{
|
|
||||||
/* no-op */
|
|
||||||
}
|
|
||||||
|
|
||||||
template <class T>
|
|
||||||
inline singleton<T>::~singleton()
|
|
||||||
{
|
|
||||||
/* no-op */
|
|
||||||
}
|
|
||||||
|
|
||||||
template <class T>
|
|
||||||
/*static*/ T &singleton<T>::instance()
|
|
||||||
{
|
|
||||||
// function-local static to force this to work correctly at static
|
|
||||||
// initialization time.
|
|
||||||
static singleton<T> s_oT;
|
|
||||||
return(s_oT);
|
|
||||||
}
|
|
||||||
|
|
||||||
} // namespace thread
|
|
||||||
} // namespace detail
|
|
||||||
} // namespace boost
|
|
||||||
|
|
||||||
#endif // BOOST_SINGLETON_MJM012402_HPP
|
|
||||||
@@ -1,78 +0,0 @@
|
|||||||
// (C) Copyright Michael Glassford 2004.
|
|
||||||
// Use, modification and distribution are subject to 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)
|
|
||||||
|
|
||||||
#if !defined(BOOST_TLS_HOOKS_HPP)
|
|
||||||
#define BOOST_TLS_HOOKS_HPP
|
|
||||||
|
|
||||||
#include <boost/thread/detail/config.hpp>
|
|
||||||
|
|
||||||
#if defined(BOOST_HAS_WINTHREADS)
|
|
||||||
|
|
||||||
typedef void (__cdecl *thread_exit_handler)(void);
|
|
||||||
|
|
||||||
extern "C" BOOST_THREAD_DECL int at_thread_exit(
|
|
||||||
thread_exit_handler exit_handler
|
|
||||||
);
|
|
||||||
//Add a function to the list of functions that will
|
|
||||||
//be called when a thread is about to exit.
|
|
||||||
//Currently only implemented for Win32, but should
|
|
||||||
//later be implemented for all platforms.
|
|
||||||
//Used by Win32 implementation of Boost.Threads
|
|
||||||
//tss to peform cleanup.
|
|
||||||
//Like the C runtime library atexit() function,
|
|
||||||
//which it mimics, at_thread_exit() returns
|
|
||||||
//zero if successful and a nonzero
|
|
||||||
//value if an error occurs.
|
|
||||||
|
|
||||||
#endif //defined(BOOST_HAS_WINTHREADS)
|
|
||||||
|
|
||||||
#if defined(BOOST_HAS_WINTHREADS)
|
|
||||||
|
|
||||||
extern "C" BOOST_THREAD_DECL void on_process_enter(void);
|
|
||||||
//Function to be called when the exe or dll
|
|
||||||
//that uses Boost.Threads first starts
|
|
||||||
//or is first loaded.
|
|
||||||
//Should be called only before the first call to
|
|
||||||
//on_thread_enter().
|
|
||||||
//Called automatically by Boost.Threads when
|
|
||||||
//a method for doing so has been discovered.
|
|
||||||
//May be omitted; may be called multiple times.
|
|
||||||
|
|
||||||
extern "C" BOOST_THREAD_DECL void on_process_exit(void);
|
|
||||||
//Function to be called when the exe or dll
|
|
||||||
//that uses Boost.Threads first starts
|
|
||||||
//or is first loaded.
|
|
||||||
//Should be called only after the last call to
|
|
||||||
//on_exit_thread().
|
|
||||||
//Called automatically by Boost.Threads when
|
|
||||||
//a method for doing so has been discovered.
|
|
||||||
//Must not be omitted; may be called multiple times.
|
|
||||||
|
|
||||||
extern "C" BOOST_THREAD_DECL void on_thread_enter(void);
|
|
||||||
//Function to be called just after a thread starts
|
|
||||||
//in an exe or dll that uses Boost.Threads.
|
|
||||||
//Must be called in the context of the thread
|
|
||||||
//that is starting.
|
|
||||||
//Called automatically by Boost.Threads when
|
|
||||||
//a method for doing so has been discovered.
|
|
||||||
//May be omitted; may be called multiple times.
|
|
||||||
|
|
||||||
extern "C" BOOST_THREAD_DECL void on_thread_exit(void);
|
|
||||||
//Function to be called just be fore a thread ends
|
|
||||||
//in an exe or dll that uses Boost.Threads.
|
|
||||||
//Must be called in the context of the thread
|
|
||||||
//that is ending.
|
|
||||||
//Called automatically by Boost.Threads when
|
|
||||||
//a method for doing so has been discovered.
|
|
||||||
//Must not be omitted; may be called multiple times.
|
|
||||||
|
|
||||||
extern "C" void tss_cleanup_implemented(void);
|
|
||||||
//Dummy function used both to detect whether tss cleanup
|
|
||||||
//cleanup has been implemented and to force
|
|
||||||
//it to be linked into the Boost.Threads library.
|
|
||||||
|
|
||||||
#endif //defined(BOOST_HAS_WINTHREADS)
|
|
||||||
|
|
||||||
#endif //!defined(BOOST_TLS_HOOKS_HPP)
|
|
||||||
@@ -1,101 +0,0 @@
|
|||||||
// 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_THREAD_EXCEPTIONS_PDM070801_H
|
|
||||||
#define BOOST_THREAD_EXCEPTIONS_PDM070801_H
|
|
||||||
|
|
||||||
#include <boost/thread/detail/config.hpp>
|
|
||||||
|
|
||||||
// pdm: Sorry, but this class is used all over the place & I end up
|
|
||||||
// with recursive headers if I don't separate it
|
|
||||||
// wek: Not sure why recursive headers would cause compilation problems
|
|
||||||
// given the include guards, but regardless it makes sense to
|
|
||||||
// seperate this out any way.
|
|
||||||
|
|
||||||
#include <string>
|
|
||||||
#include <stdexcept>
|
|
||||||
|
|
||||||
namespace boost {
|
|
||||||
|
|
||||||
class BOOST_THREAD_DECL thread_exception : public std::exception
|
|
||||||
{
|
|
||||||
protected:
|
|
||||||
thread_exception();
|
|
||||||
thread_exception(int sys_err_code);
|
|
||||||
|
|
||||||
public:
|
|
||||||
~thread_exception() throw();
|
|
||||||
|
|
||||||
int native_error() const;
|
|
||||||
|
|
||||||
const char* message() const;
|
|
||||||
|
|
||||||
private:
|
|
||||||
int m_sys_err;
|
|
||||||
};
|
|
||||||
|
|
||||||
class BOOST_THREAD_DECL lock_error : public thread_exception
|
|
||||||
{
|
|
||||||
public:
|
|
||||||
lock_error();
|
|
||||||
lock_error(int sys_err_code);
|
|
||||||
~lock_error() throw();
|
|
||||||
|
|
||||||
virtual const char* what() const throw();
|
|
||||||
};
|
|
||||||
|
|
||||||
class BOOST_THREAD_DECL thread_resource_error : public thread_exception
|
|
||||||
{
|
|
||||||
public:
|
|
||||||
thread_resource_error();
|
|
||||||
thread_resource_error(int sys_err_code);
|
|
||||||
~thread_resource_error() throw();
|
|
||||||
|
|
||||||
virtual const char* what() const throw();
|
|
||||||
};
|
|
||||||
|
|
||||||
class BOOST_THREAD_DECL unsupported_thread_option : public thread_exception
|
|
||||||
{
|
|
||||||
public:
|
|
||||||
unsupported_thread_option();
|
|
||||||
unsupported_thread_option(int sys_err_code);
|
|
||||||
~unsupported_thread_option() throw();
|
|
||||||
|
|
||||||
virtual const char* what() const throw();
|
|
||||||
};
|
|
||||||
|
|
||||||
class BOOST_THREAD_DECL invalid_thread_argument : public thread_exception
|
|
||||||
{
|
|
||||||
public:
|
|
||||||
invalid_thread_argument();
|
|
||||||
invalid_thread_argument(int sys_err_code);
|
|
||||||
~invalid_thread_argument() throw();
|
|
||||||
|
|
||||||
virtual const char* what() const throw();
|
|
||||||
};
|
|
||||||
|
|
||||||
class BOOST_THREAD_DECL thread_permission_error : public thread_exception
|
|
||||||
{
|
|
||||||
public:
|
|
||||||
thread_permission_error();
|
|
||||||
thread_permission_error(int sys_err_code);
|
|
||||||
~thread_permission_error() throw();
|
|
||||||
|
|
||||||
virtual const char* what() const throw();
|
|
||||||
};
|
|
||||||
|
|
||||||
} // namespace boost
|
|
||||||
|
|
||||||
#endif // BOOST_THREAD_CONFIG_PDM070801_H
|
|
||||||
|
|
||||||
// Change log:
|
|
||||||
// 3 Jan 03 WEKEMPF Modified for DLL implementation.
|
|
||||||
|
|
||||||
@@ -1,167 +0,0 @@
|
|||||||
// 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_MUTEX_WEK070601_HPP
|
|
||||||
#define BOOST_MUTEX_WEK070601_HPP
|
|
||||||
|
|
||||||
#include <boost/thread/detail/config.hpp>
|
|
||||||
|
|
||||||
#include <boost/utility.hpp>
|
|
||||||
#include <boost/thread/detail/lock.hpp>
|
|
||||||
|
|
||||||
#if defined(BOOST_HAS_PTHREADS)
|
|
||||||
# include <pthread.h>
|
|
||||||
#endif
|
|
||||||
|
|
||||||
#if defined(BOOST_HAS_MPTASKS)
|
|
||||||
# include "scoped_critical_region.hpp"
|
|
||||||
#endif
|
|
||||||
|
|
||||||
namespace boost {
|
|
||||||
|
|
||||||
struct xtime;
|
|
||||||
|
|
||||||
class BOOST_THREAD_DECL mutex
|
|
||||||
: private noncopyable
|
|
||||||
{
|
|
||||||
public:
|
|
||||||
friend class detail::thread::lock_ops<mutex>;
|
|
||||||
|
|
||||||
typedef detail::thread::scoped_lock<mutex> scoped_lock;
|
|
||||||
|
|
||||||
mutex();
|
|
||||||
~mutex();
|
|
||||||
|
|
||||||
private:
|
|
||||||
#if defined(BOOST_HAS_WINTHREADS)
|
|
||||||
typedef void* cv_state;
|
|
||||||
#elif defined(BOOST_HAS_PTHREADS)
|
|
||||||
struct cv_state
|
|
||||||
{
|
|
||||||
pthread_mutex_t* pmutex;
|
|
||||||
};
|
|
||||||
#elif defined(BOOST_HAS_MPTASKS)
|
|
||||||
struct cv_state
|
|
||||||
{
|
|
||||||
};
|
|
||||||
#endif
|
|
||||||
void do_lock();
|
|
||||||
void do_unlock();
|
|
||||||
void do_lock(cv_state& state);
|
|
||||||
void do_unlock(cv_state& state);
|
|
||||||
|
|
||||||
#if defined(BOOST_HAS_WINTHREADS)
|
|
||||||
void* m_mutex;
|
|
||||||
bool m_critical_section;
|
|
||||||
#elif defined(BOOST_HAS_PTHREADS)
|
|
||||||
pthread_mutex_t m_mutex;
|
|
||||||
#elif defined(BOOST_HAS_MPTASKS)
|
|
||||||
threads::mac::detail::scoped_critical_region m_mutex;
|
|
||||||
threads::mac::detail::scoped_critical_region m_mutex_mutex;
|
|
||||||
#endif
|
|
||||||
};
|
|
||||||
|
|
||||||
class BOOST_THREAD_DECL try_mutex
|
|
||||||
: private noncopyable
|
|
||||||
{
|
|
||||||
public:
|
|
||||||
friend class detail::thread::lock_ops<try_mutex>;
|
|
||||||
|
|
||||||
typedef detail::thread::scoped_lock<try_mutex> scoped_lock;
|
|
||||||
typedef detail::thread::scoped_try_lock<try_mutex> scoped_try_lock;
|
|
||||||
|
|
||||||
try_mutex();
|
|
||||||
~try_mutex();
|
|
||||||
|
|
||||||
private:
|
|
||||||
#if defined(BOOST_HAS_WINTHREADS)
|
|
||||||
typedef void* cv_state;
|
|
||||||
#elif defined(BOOST_HAS_PTHREADS)
|
|
||||||
struct cv_state
|
|
||||||
{
|
|
||||||
pthread_mutex_t* pmutex;
|
|
||||||
};
|
|
||||||
#elif defined(BOOST_HAS_MPTASKS)
|
|
||||||
struct cv_state
|
|
||||||
{
|
|
||||||
};
|
|
||||||
#endif
|
|
||||||
void do_lock();
|
|
||||||
bool do_trylock();
|
|
||||||
void do_unlock();
|
|
||||||
void do_lock(cv_state& state);
|
|
||||||
void do_unlock(cv_state& state);
|
|
||||||
|
|
||||||
#if defined(BOOST_HAS_WINTHREADS)
|
|
||||||
void* m_mutex;
|
|
||||||
bool m_critical_section;
|
|
||||||
#elif defined(BOOST_HAS_PTHREADS)
|
|
||||||
pthread_mutex_t m_mutex;
|
|
||||||
#elif defined(BOOST_HAS_MPTASKS)
|
|
||||||
threads::mac::detail::scoped_critical_region m_mutex;
|
|
||||||
threads::mac::detail::scoped_critical_region m_mutex_mutex;
|
|
||||||
#endif
|
|
||||||
};
|
|
||||||
|
|
||||||
class BOOST_THREAD_DECL timed_mutex
|
|
||||||
: private noncopyable
|
|
||||||
{
|
|
||||||
public:
|
|
||||||
friend class detail::thread::lock_ops<timed_mutex>;
|
|
||||||
|
|
||||||
typedef detail::thread::scoped_lock<timed_mutex> scoped_lock;
|
|
||||||
typedef detail::thread::scoped_try_lock<timed_mutex> scoped_try_lock;
|
|
||||||
typedef detail::thread::scoped_timed_lock<timed_mutex> scoped_timed_lock;
|
|
||||||
|
|
||||||
timed_mutex();
|
|
||||||
~timed_mutex();
|
|
||||||
|
|
||||||
private:
|
|
||||||
#if defined(BOOST_HAS_WINTHREADS)
|
|
||||||
typedef void* cv_state;
|
|
||||||
#elif defined(BOOST_HAS_PTHREADS)
|
|
||||||
struct cv_state
|
|
||||||
{
|
|
||||||
pthread_mutex_t* pmutex;
|
|
||||||
};
|
|
||||||
#elif defined(BOOST_HAS_MPTASKS)
|
|
||||||
struct cv_state
|
|
||||||
{
|
|
||||||
};
|
|
||||||
#endif
|
|
||||||
void do_lock();
|
|
||||||
bool do_trylock();
|
|
||||||
bool do_timedlock(const xtime& xt);
|
|
||||||
void do_unlock();
|
|
||||||
void do_lock(cv_state& state);
|
|
||||||
void do_unlock(cv_state& state);
|
|
||||||
|
|
||||||
#if defined(BOOST_HAS_WINTHREADS)
|
|
||||||
void* m_mutex;
|
|
||||||
#elif defined(BOOST_HAS_PTHREADS)
|
|
||||||
pthread_mutex_t m_mutex;
|
|
||||||
pthread_cond_t m_condition;
|
|
||||||
bool m_locked;
|
|
||||||
#elif defined(BOOST_HAS_MPTASKS)
|
|
||||||
threads::mac::detail::scoped_critical_region m_mutex;
|
|
||||||
threads::mac::detail::scoped_critical_region m_mutex_mutex;
|
|
||||||
#endif
|
|
||||||
};
|
|
||||||
|
|
||||||
} // namespace boost
|
|
||||||
|
|
||||||
// Change Log:
|
|
||||||
// 8 Feb 01 WEKEMPF Initial version.
|
|
||||||
// 22 May 01 WEKEMPF Modified to use xtime for time outs. Factored out
|
|
||||||
// to three classes, mutex, try_mutex and timed_mutex.
|
|
||||||
// 3 Jan 03 WEKEMPF Modified for DLL implementation.
|
|
||||||
|
|
||||||
#endif // BOOST_MUTEX_WEK070601_HPP
|
|
||||||
@@ -1,42 +0,0 @@
|
|||||||
// 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_ONCE_WEK080101_HPP
|
|
||||||
#define BOOST_ONCE_WEK080101_HPP
|
|
||||||
|
|
||||||
#include <boost/thread/detail/config.hpp>
|
|
||||||
|
|
||||||
#if defined(BOOST_HAS_PTHREADS)
|
|
||||||
# include <pthread.h>
|
|
||||||
#endif
|
|
||||||
|
|
||||||
namespace boost {
|
|
||||||
|
|
||||||
#if defined(BOOST_HAS_PTHREADS)
|
|
||||||
|
|
||||||
typedef pthread_once_t once_flag;
|
|
||||||
#define BOOST_ONCE_INIT PTHREAD_ONCE_INIT
|
|
||||||
|
|
||||||
#elif (defined(BOOST_HAS_WINTHREADS) || defined(BOOST_HAS_MPTASKS))
|
|
||||||
|
|
||||||
typedef long once_flag;
|
|
||||||
#define BOOST_ONCE_INIT 0
|
|
||||||
|
|
||||||
#endif
|
|
||||||
|
|
||||||
void BOOST_THREAD_DECL call_once(void (*func)(), once_flag& flag);
|
|
||||||
|
|
||||||
} // namespace boost
|
|
||||||
|
|
||||||
// Change Log:
|
|
||||||
// 1 Aug 01 WEKEMPF Initial version.
|
|
||||||
|
|
||||||
#endif // BOOST_ONCE_WEK080101_HPP
|
|
||||||
@@ -1,273 +0,0 @@
|
|||||||
// Copyright (C) 2002-2003
|
|
||||||
// David Moore, 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. David Moore makes no representations
|
|
||||||
// about the suitability of this software for any purpose.
|
|
||||||
// It is provided "as is" without express or implied warranty.
|
|
||||||
|
|
||||||
// A Boost::threads implementation of a synchronization
|
|
||||||
// primitive which can allow multiple readers or a single
|
|
||||||
// writer to have access to a shared resource.
|
|
||||||
|
|
||||||
#ifndef BOOST_READ_WRITE_MUTEX_JDM030602_HPP
|
|
||||||
#define BOOST_READ_WRITE_MUTEX_JDM030602_HPP
|
|
||||||
|
|
||||||
#include <boost/thread/detail/config.hpp>
|
|
||||||
|
|
||||||
#include <boost/utility.hpp>
|
|
||||||
|
|
||||||
#include <boost/thread/mutex.hpp>
|
|
||||||
#include <boost/thread/detail/lock.hpp>
|
|
||||||
#include <boost/thread/detail/read_write_lock.hpp>
|
|
||||||
#include <boost/thread/condition.hpp>
|
|
||||||
|
|
||||||
namespace boost {
|
|
||||||
|
|
||||||
namespace read_write_scheduling_policy {
|
|
||||||
enum read_write_scheduling_policy_enum
|
|
||||||
{
|
|
||||||
writer_priority, //Prefer writers; can starve readers
|
|
||||||
reader_priority, //Prefer readers; can starve writers
|
|
||||||
alternating_many_reads, //Alternate readers and writers; before a writer, release all queued readers
|
|
||||||
alternating_single_read //Alternate readers and writers; before a writer, release only on queued reader
|
|
||||||
};
|
|
||||||
} // namespace read_write_scheduling_policy
|
|
||||||
|
|
||||||
namespace detail {
|
|
||||||
|
|
||||||
namespace thread {
|
|
||||||
|
|
||||||
// Shared implementation construct for explicit Scheduling Policies
|
|
||||||
// This implementation is susceptible to self-deadlock, though....
|
|
||||||
template<typename Mutex>
|
|
||||||
struct read_write_mutex_impl
|
|
||||||
{
|
|
||||||
typedef Mutex mutex_type;
|
|
||||||
typedef detail::thread::scoped_lock<Mutex> scoped_lock;
|
|
||||||
typedef detail::thread::scoped_try_lock<Mutex> scoped_try_lock;
|
|
||||||
typedef detail::thread::scoped_timed_lock<Mutex> scoped_timed_lock;
|
|
||||||
|
|
||||||
read_write_mutex_impl(read_write_scheduling_policy::read_write_scheduling_policy_enum sp)
|
|
||||||
: m_num_waiting_writers(0),
|
|
||||||
m_num_waiting_readers(0),
|
|
||||||
m_num_readers_to_wake(0),
|
|
||||||
m_state_waiting_promotion(false),
|
|
||||||
m_state(0),
|
|
||||||
m_sp(sp),
|
|
||||||
m_readers_next(true) { }
|
|
||||||
|
|
||||||
Mutex m_prot;
|
|
||||||
boost::condition m_waiting_writers;
|
|
||||||
boost::condition m_waiting_readers;
|
|
||||||
int m_num_waiting_writers;
|
|
||||||
int m_num_waiting_readers;
|
|
||||||
int m_num_readers_to_wake;
|
|
||||||
boost::condition m_waiting_promotion;
|
|
||||||
bool m_state_waiting_promotion;
|
|
||||||
int m_state; // -1 = excl locked
|
|
||||||
// 0 = unlocked
|
|
||||||
// 1-> INT_MAX - shared locked
|
|
||||||
const read_write_scheduling_policy::read_write_scheduling_policy_enum m_sp;
|
|
||||||
bool m_readers_next;
|
|
||||||
|
|
||||||
void do_read_lock();
|
|
||||||
void do_write_lock();
|
|
||||||
void do_write_unlock();
|
|
||||||
void do_read_unlock();
|
|
||||||
bool do_try_write_lock();
|
|
||||||
bool do_try_read_lock();
|
|
||||||
bool do_timed_write_lock(const xtime &xt);
|
|
||||||
bool do_timed_read_lock(const xtime &xt);
|
|
||||||
|
|
||||||
void do_demote_to_read_lock();
|
|
||||||
bool do_try_demote_to_read_lock();
|
|
||||||
bool do_timed_demote_to_read_lock(const xtime &xt);
|
|
||||||
|
|
||||||
void do_promote_to_write_lock();
|
|
||||||
bool do_try_promote_to_write_lock();
|
|
||||||
bool do_timed_promote_to_write_lock(const xtime &xt);
|
|
||||||
|
|
||||||
bool locked();
|
|
||||||
read_write_lock_state::read_write_lock_state_enum state();
|
|
||||||
|
|
||||||
private:
|
|
||||||
|
|
||||||
void do_unlock_scheduling_impl();
|
|
||||||
void do_timeout_scheduling_impl();
|
|
||||||
void do_demote_scheduling_impl();
|
|
||||||
void do_scheduling_impl();
|
|
||||||
|
|
||||||
bool do_demote_to_read_lock_impl();
|
|
||||||
};
|
|
||||||
|
|
||||||
} // namespace detail
|
|
||||||
|
|
||||||
} // namespace thread
|
|
||||||
|
|
||||||
class BOOST_THREAD_DECL read_write_mutex : private noncopyable
|
|
||||||
{
|
|
||||||
public:
|
|
||||||
|
|
||||||
read_write_mutex(read_write_scheduling_policy::read_write_scheduling_policy_enum sp) : m_impl(sp) { }
|
|
||||||
~read_write_mutex() { }
|
|
||||||
|
|
||||||
read_write_scheduling_policy::read_write_scheduling_policy_enum policy() const { return m_impl.m_sp; }
|
|
||||||
|
|
||||||
friend class detail::thread::read_write_lock_ops<read_write_mutex>;
|
|
||||||
|
|
||||||
typedef detail::thread::scoped_read_write_lock<
|
|
||||||
read_write_mutex> scoped_read_write_lock;
|
|
||||||
|
|
||||||
typedef detail::thread::scoped_read_lock<
|
|
||||||
read_write_mutex> scoped_read_lock;
|
|
||||||
|
|
||||||
typedef detail::thread::scoped_write_lock<
|
|
||||||
read_write_mutex> scoped_write_lock;
|
|
||||||
|
|
||||||
private:
|
|
||||||
|
|
||||||
// Operations that will eventually be done only
|
|
||||||
// via lock types
|
|
||||||
void do_write_lock();
|
|
||||||
void do_read_lock();
|
|
||||||
void do_write_unlock();
|
|
||||||
void do_read_unlock();
|
|
||||||
|
|
||||||
void do_demote_to_read_lock();
|
|
||||||
|
|
||||||
void do_promote_to_write_lock();
|
|
||||||
|
|
||||||
bool locked();
|
|
||||||
read_write_lock_state::read_write_lock_state_enum state();
|
|
||||||
|
|
||||||
detail::thread::read_write_mutex_impl<mutex> m_impl;
|
|
||||||
};
|
|
||||||
|
|
||||||
class BOOST_THREAD_DECL try_read_write_mutex : private noncopyable
|
|
||||||
{
|
|
||||||
public:
|
|
||||||
|
|
||||||
try_read_write_mutex(read_write_scheduling_policy::read_write_scheduling_policy_enum sp) : m_impl(sp) { }
|
|
||||||
~try_read_write_mutex() { }
|
|
||||||
|
|
||||||
read_write_scheduling_policy::read_write_scheduling_policy_enum policy() const { return m_impl.m_sp; }
|
|
||||||
|
|
||||||
friend class detail::thread::read_write_lock_ops<try_read_write_mutex>;
|
|
||||||
|
|
||||||
typedef detail::thread::scoped_read_write_lock<
|
|
||||||
try_read_write_mutex> scoped_read_write_lock;
|
|
||||||
typedef detail::thread::scoped_try_read_write_lock<
|
|
||||||
try_read_write_mutex> scoped_try_read_write_lock;
|
|
||||||
|
|
||||||
typedef detail::thread::scoped_read_lock<
|
|
||||||
try_read_write_mutex> scoped_read_lock;
|
|
||||||
typedef detail::thread::scoped_try_read_lock<
|
|
||||||
try_read_write_mutex> scoped_try_read_lock;
|
|
||||||
|
|
||||||
typedef detail::thread::scoped_write_lock<
|
|
||||||
try_read_write_mutex> scoped_write_lock;
|
|
||||||
typedef detail::thread::scoped_try_write_lock<
|
|
||||||
try_read_write_mutex> scoped_try_write_lock;
|
|
||||||
|
|
||||||
private:
|
|
||||||
|
|
||||||
// Operations that will eventually be done only
|
|
||||||
// via lock types
|
|
||||||
void do_write_lock();
|
|
||||||
void do_read_lock();
|
|
||||||
void do_write_unlock();
|
|
||||||
void do_read_unlock();
|
|
||||||
bool do_try_write_lock();
|
|
||||||
bool do_try_read_lock();
|
|
||||||
|
|
||||||
|
|
||||||
void do_demote_to_read_lock();
|
|
||||||
bool do_try_demote_to_read_lock();
|
|
||||||
|
|
||||||
void do_promote_to_write_lock();
|
|
||||||
bool do_try_promote_to_write_lock();
|
|
||||||
|
|
||||||
bool locked();
|
|
||||||
read_write_lock_state::read_write_lock_state_enum state();
|
|
||||||
|
|
||||||
detail::thread::read_write_mutex_impl<try_mutex> m_impl;
|
|
||||||
};
|
|
||||||
|
|
||||||
class BOOST_THREAD_DECL timed_read_write_mutex : private noncopyable
|
|
||||||
{
|
|
||||||
public:
|
|
||||||
|
|
||||||
timed_read_write_mutex(read_write_scheduling_policy::read_write_scheduling_policy_enum sp) : m_impl(sp) { }
|
|
||||||
~timed_read_write_mutex() { }
|
|
||||||
|
|
||||||
read_write_scheduling_policy::read_write_scheduling_policy_enum policy() const { return m_impl.m_sp; }
|
|
||||||
|
|
||||||
friend class detail::thread::read_write_lock_ops<timed_read_write_mutex>;
|
|
||||||
|
|
||||||
typedef detail::thread::scoped_read_write_lock<
|
|
||||||
timed_read_write_mutex> scoped_read_write_lock;
|
|
||||||
typedef detail::thread::scoped_try_read_write_lock<
|
|
||||||
timed_read_write_mutex> scoped_try_read_write_lock;
|
|
||||||
typedef detail::thread::scoped_timed_read_write_lock<
|
|
||||||
timed_read_write_mutex> scoped_timed_read_write_lock;
|
|
||||||
|
|
||||||
typedef detail::thread::scoped_read_lock<
|
|
||||||
timed_read_write_mutex> scoped_read_lock;
|
|
||||||
typedef detail::thread::scoped_try_read_lock<
|
|
||||||
timed_read_write_mutex> scoped_try_read_lock;
|
|
||||||
typedef detail::thread::scoped_timed_read_lock<
|
|
||||||
timed_read_write_mutex> scoped_timed_read_lock;
|
|
||||||
|
|
||||||
typedef detail::thread::scoped_write_lock<
|
|
||||||
timed_read_write_mutex> scoped_write_lock;
|
|
||||||
typedef detail::thread::scoped_try_write_lock<
|
|
||||||
timed_read_write_mutex> scoped_try_write_lock;
|
|
||||||
typedef detail::thread::scoped_timed_write_lock<
|
|
||||||
timed_read_write_mutex> scoped_timed_write_lock;
|
|
||||||
|
|
||||||
private:
|
|
||||||
|
|
||||||
// Operations that will eventually be done only
|
|
||||||
// via lock types
|
|
||||||
void do_write_lock();
|
|
||||||
void do_read_lock();
|
|
||||||
void do_write_unlock();
|
|
||||||
void do_read_unlock();
|
|
||||||
bool do_try_write_lock();
|
|
||||||
bool do_try_read_lock();
|
|
||||||
bool do_timed_write_lock(const xtime &xt);
|
|
||||||
bool do_timed_read_lock(const xtime &xt);
|
|
||||||
|
|
||||||
void do_demote_to_read_lock();
|
|
||||||
bool do_try_demote_to_read_lock();
|
|
||||||
bool do_timed_demote_to_read_lock(const xtime &xt);
|
|
||||||
|
|
||||||
void do_promote_to_write_lock();
|
|
||||||
bool do_try_promote_to_write_lock();
|
|
||||||
bool do_timed_promote_to_write_lock(const xtime &xt);
|
|
||||||
|
|
||||||
bool locked();
|
|
||||||
read_write_lock_state::read_write_lock_state_enum state();
|
|
||||||
|
|
||||||
detail::thread::read_write_mutex_impl<timed_mutex> m_impl;
|
|
||||||
};
|
|
||||||
|
|
||||||
} // namespace boost
|
|
||||||
|
|
||||||
#endif
|
|
||||||
|
|
||||||
// Change Log:
|
|
||||||
// 10 Mar 02
|
|
||||||
// Original version.
|
|
||||||
// 4 May 04 GlassfordM
|
|
||||||
// Implement lock promotion and demotion.
|
|
||||||
// Add locked() and state() member functions for debugging
|
|
||||||
// (should these be made public?).
|
|
||||||
// Rename to improve consistency and eliminate abbreviations:
|
|
||||||
// Use "read" and "write" instead of "shared" and "exclusive".
|
|
||||||
// Change "rd" to "read", "wr" to "write", "rw" to "read_write".
|
|
||||||
// Add mutex_type typdef.
|
|
||||||
@@ -1,182 +0,0 @@
|
|||||||
// 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_RECURSIVE_MUTEX_WEK070601_HPP
|
|
||||||
#define BOOST_RECURSIVE_MUTEX_WEK070601_HPP
|
|
||||||
|
|
||||||
#include <boost/thread/detail/config.hpp>
|
|
||||||
|
|
||||||
#include <boost/utility.hpp>
|
|
||||||
#include <boost/thread/detail/lock.hpp>
|
|
||||||
|
|
||||||
#if defined(BOOST_HAS_PTHREADS)
|
|
||||||
# include <pthread.h>
|
|
||||||
#endif
|
|
||||||
|
|
||||||
#if defined(BOOST_HAS_MPTASKS)
|
|
||||||
# include "scoped_critical_region.hpp"
|
|
||||||
#endif
|
|
||||||
|
|
||||||
namespace boost {
|
|
||||||
|
|
||||||
struct xtime;
|
|
||||||
|
|
||||||
class BOOST_THREAD_DECL recursive_mutex
|
|
||||||
: private noncopyable
|
|
||||||
{
|
|
||||||
public:
|
|
||||||
friend class detail::thread::lock_ops<recursive_mutex>;
|
|
||||||
|
|
||||||
typedef detail::thread::scoped_lock<recursive_mutex> scoped_lock;
|
|
||||||
|
|
||||||
recursive_mutex();
|
|
||||||
~recursive_mutex();
|
|
||||||
|
|
||||||
private:
|
|
||||||
#if (defined(BOOST_HAS_WINTHREADS) || defined(BOOST_HAS_MPTASKS))
|
|
||||||
typedef std::size_t cv_state;
|
|
||||||
#elif defined(BOOST_HAS_PTHREADS)
|
|
||||||
struct cv_state
|
|
||||||
{
|
|
||||||
long count;
|
|
||||||
pthread_mutex_t* pmutex;
|
|
||||||
};
|
|
||||||
#endif
|
|
||||||
void do_lock();
|
|
||||||
void do_unlock();
|
|
||||||
void do_lock(cv_state& state);
|
|
||||||
void do_unlock(cv_state& state);
|
|
||||||
|
|
||||||
#if defined(BOOST_HAS_WINTHREADS)
|
|
||||||
void* m_mutex;
|
|
||||||
bool m_critical_section;
|
|
||||||
unsigned long m_count;
|
|
||||||
#elif defined(BOOST_HAS_PTHREADS)
|
|
||||||
pthread_mutex_t m_mutex;
|
|
||||||
unsigned m_count;
|
|
||||||
# if !defined(BOOST_HAS_PTHREAD_MUTEXATTR_SETTYPE)
|
|
||||||
pthread_cond_t m_unlocked;
|
|
||||||
pthread_t m_thread_id;
|
|
||||||
bool m_valid_id;
|
|
||||||
# endif
|
|
||||||
#elif defined(BOOST_HAS_MPTASKS)
|
|
||||||
threads::mac::detail::scoped_critical_region m_mutex;
|
|
||||||
threads::mac::detail::scoped_critical_region m_mutex_mutex;
|
|
||||||
std::size_t m_count;
|
|
||||||
#endif
|
|
||||||
};
|
|
||||||
|
|
||||||
class BOOST_THREAD_DECL recursive_try_mutex
|
|
||||||
: private noncopyable
|
|
||||||
{
|
|
||||||
public:
|
|
||||||
friend class detail::thread::lock_ops<recursive_try_mutex>;
|
|
||||||
|
|
||||||
typedef detail::thread::scoped_lock<recursive_try_mutex> scoped_lock;
|
|
||||||
typedef detail::thread::scoped_try_lock<
|
|
||||||
recursive_try_mutex> scoped_try_lock;
|
|
||||||
|
|
||||||
recursive_try_mutex();
|
|
||||||
~recursive_try_mutex();
|
|
||||||
|
|
||||||
private:
|
|
||||||
#if (defined(BOOST_HAS_WINTHREADS) || defined(BOOST_HAS_MPTASKS))
|
|
||||||
typedef std::size_t cv_state;
|
|
||||||
#elif defined(BOOST_HAS_PTHREADS)
|
|
||||||
struct cv_state
|
|
||||||
{
|
|
||||||
long count;
|
|
||||||
pthread_mutex_t* pmutex;
|
|
||||||
};
|
|
||||||
#endif
|
|
||||||
void do_lock();
|
|
||||||
bool do_trylock();
|
|
||||||
void do_unlock();
|
|
||||||
void do_lock(cv_state& state);
|
|
||||||
void do_unlock(cv_state& state);
|
|
||||||
|
|
||||||
#if defined(BOOST_HAS_WINTHREADS)
|
|
||||||
void* m_mutex;
|
|
||||||
bool m_critical_section;
|
|
||||||
unsigned long m_count;
|
|
||||||
#elif defined(BOOST_HAS_PTHREADS)
|
|
||||||
pthread_mutex_t m_mutex;
|
|
||||||
unsigned m_count;
|
|
||||||
# if !defined(BOOST_HAS_PTHREAD_MUTEXATTR_SETTYPE)
|
|
||||||
pthread_cond_t m_unlocked;
|
|
||||||
pthread_t m_thread_id;
|
|
||||||
bool m_valid_id;
|
|
||||||
# endif
|
|
||||||
#elif defined(BOOST_HAS_MPTASKS)
|
|
||||||
threads::mac::detail::scoped_critical_region m_mutex;
|
|
||||||
threads::mac::detail::scoped_critical_region m_mutex_mutex;
|
|
||||||
std::size_t m_count;
|
|
||||||
#endif
|
|
||||||
};
|
|
||||||
|
|
||||||
class BOOST_THREAD_DECL recursive_timed_mutex
|
|
||||||
: private noncopyable
|
|
||||||
{
|
|
||||||
public:
|
|
||||||
friend class detail::thread::lock_ops<recursive_timed_mutex>;
|
|
||||||
|
|
||||||
typedef detail::thread::scoped_lock<recursive_timed_mutex> scoped_lock;
|
|
||||||
typedef detail::thread::scoped_try_lock<
|
|
||||||
recursive_timed_mutex> scoped_try_lock;
|
|
||||||
typedef detail::thread::scoped_timed_lock<
|
|
||||||
recursive_timed_mutex> scoped_timed_lock;
|
|
||||||
|
|
||||||
recursive_timed_mutex();
|
|
||||||
~recursive_timed_mutex();
|
|
||||||
|
|
||||||
private:
|
|
||||||
#if (defined(BOOST_HAS_WINTHREADS) || defined(BOOST_HAS_MPTASKS))
|
|
||||||
typedef std::size_t cv_state;
|
|
||||||
#elif defined(BOOST_HAS_PTHREADS)
|
|
||||||
struct cv_state
|
|
||||||
{
|
|
||||||
long count;
|
|
||||||
pthread_mutex_t* pmutex;
|
|
||||||
};
|
|
||||||
#endif
|
|
||||||
void do_lock();
|
|
||||||
bool do_trylock();
|
|
||||||
bool do_timedlock(const xtime& xt);
|
|
||||||
void do_unlock();
|
|
||||||
void do_lock(cv_state& state);
|
|
||||||
void do_unlock(cv_state& state);
|
|
||||||
|
|
||||||
#if defined(BOOST_HAS_WINTHREADS)
|
|
||||||
void* m_mutex;
|
|
||||||
unsigned long m_count;
|
|
||||||
#elif defined(BOOST_HAS_PTHREADS)
|
|
||||||
pthread_mutex_t m_mutex;
|
|
||||||
pthread_cond_t m_unlocked;
|
|
||||||
pthread_t m_thread_id;
|
|
||||||
bool m_valid_id;
|
|
||||||
unsigned m_count;
|
|
||||||
#elif defined(BOOST_HAS_MPTASKS)
|
|
||||||
threads::mac::detail::scoped_critical_region m_mutex;
|
|
||||||
threads::mac::detail::scoped_critical_region m_mutex_mutex;
|
|
||||||
std::size_t m_count;
|
|
||||||
#endif
|
|
||||||
};
|
|
||||||
|
|
||||||
} // namespace boost
|
|
||||||
|
|
||||||
#endif // BOOST_RECURSIVE_MUTEX_WEK070601_HPP
|
|
||||||
|
|
||||||
// Change Log:
|
|
||||||
// 8 Feb 01 WEKEMPF Initial version.
|
|
||||||
// 1 Jun 01 WEKEMPF Modified to use xtime for time outs. Factored out
|
|
||||||
// to three classes, mutex, try_mutex and timed_mutex.
|
|
||||||
// 11 Jun 01 WEKEMPF Modified to use PTHREAD_MUTEX_RECURSIVE if available.
|
|
||||||
// 3 Jan 03 WEKEMPF Modified for DLL implementation.
|
|
||||||
@@ -1,86 +0,0 @@
|
|||||||
// 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_THREAD_WEK070601_HPP
|
|
||||||
#define BOOST_THREAD_WEK070601_HPP
|
|
||||||
|
|
||||||
#include <boost/thread/detail/config.hpp>
|
|
||||||
|
|
||||||
#include <boost/utility.hpp>
|
|
||||||
#include <boost/function.hpp>
|
|
||||||
#include <boost/thread/mutex.hpp>
|
|
||||||
#include <list>
|
|
||||||
#include <memory>
|
|
||||||
|
|
||||||
#if defined(BOOST_HAS_PTHREADS)
|
|
||||||
# include <pthread.h>
|
|
||||||
# include <boost/thread/condition.hpp>
|
|
||||||
#elif defined(BOOST_HAS_MPTASKS)
|
|
||||||
# include <Multiprocessing.h>
|
|
||||||
#endif
|
|
||||||
|
|
||||||
namespace boost {
|
|
||||||
|
|
||||||
struct xtime;
|
|
||||||
|
|
||||||
class BOOST_THREAD_DECL thread : private noncopyable
|
|
||||||
{
|
|
||||||
public:
|
|
||||||
thread();
|
|
||||||
explicit thread(const function0<void>& threadfunc);
|
|
||||||
~thread();
|
|
||||||
|
|
||||||
bool operator==(const thread& other) const;
|
|
||||||
bool operator!=(const thread& other) const;
|
|
||||||
|
|
||||||
void join();
|
|
||||||
|
|
||||||
static void sleep(const xtime& xt);
|
|
||||||
static void yield();
|
|
||||||
|
|
||||||
private:
|
|
||||||
#if defined(BOOST_HAS_WINTHREADS)
|
|
||||||
void* m_thread;
|
|
||||||
unsigned int m_id;
|
|
||||||
#elif defined(BOOST_HAS_PTHREADS)
|
|
||||||
private:
|
|
||||||
pthread_t m_thread;
|
|
||||||
#elif defined(BOOST_HAS_MPTASKS)
|
|
||||||
MPQueueID m_pJoinQueueID;
|
|
||||||
MPTaskID m_pTaskID;
|
|
||||||
#endif
|
|
||||||
bool m_joinable;
|
|
||||||
};
|
|
||||||
|
|
||||||
class BOOST_THREAD_DECL thread_group : private noncopyable
|
|
||||||
{
|
|
||||||
public:
|
|
||||||
thread_group();
|
|
||||||
~thread_group();
|
|
||||||
|
|
||||||
thread* create_thread(const function0<void>& threadfunc);
|
|
||||||
void add_thread(thread* thrd);
|
|
||||||
void remove_thread(thread* thrd);
|
|
||||||
void join_all();
|
|
||||||
|
|
||||||
private:
|
|
||||||
std::list<thread*> m_threads;
|
|
||||||
mutex m_mutex;
|
|
||||||
};
|
|
||||||
|
|
||||||
} // namespace boost
|
|
||||||
|
|
||||||
// Change Log:
|
|
||||||
// 8 Feb 01 WEKEMPF Initial version.
|
|
||||||
// 1 Jun 01 WEKEMPF Added boost::thread initial implementation.
|
|
||||||
// 3 Jul 01 WEKEMPF Redesigned boost::thread to be noncopyable.
|
|
||||||
|
|
||||||
#endif // BOOST_THREAD_WEK070601_HPP
|
|
||||||
@@ -1,121 +0,0 @@
|
|||||||
// 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_TSS_WEK070601_HPP
|
|
||||||
#define BOOST_TSS_WEK070601_HPP
|
|
||||||
|
|
||||||
#include <boost/thread/detail/config.hpp>
|
|
||||||
|
|
||||||
#include <boost/utility.hpp>
|
|
||||||
#include <boost/function.hpp>
|
|
||||||
#include <boost/thread/exceptions.hpp>
|
|
||||||
|
|
||||||
#if defined(BOOST_HAS_PTHREADS)
|
|
||||||
# include <pthread.h>
|
|
||||||
#elif defined(BOOST_HAS_MPTASKS)
|
|
||||||
# include <Multiprocessing.h>
|
|
||||||
#endif
|
|
||||||
|
|
||||||
namespace boost {
|
|
||||||
|
|
||||||
namespace detail {
|
|
||||||
|
|
||||||
class BOOST_THREAD_DECL tss : private noncopyable
|
|
||||||
{
|
|
||||||
public:
|
|
||||||
tss(boost::function1<void, void*>* pcleanup) {
|
|
||||||
if (pcleanup == 0) throw boost::thread_resource_error();
|
|
||||||
try
|
|
||||||
{
|
|
||||||
init(pcleanup);
|
|
||||||
}
|
|
||||||
catch (...)
|
|
||||||
{
|
|
||||||
delete pcleanup;
|
|
||||||
throw boost::thread_resource_error();
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
void* get() const;
|
|
||||||
void set(void* value);
|
|
||||||
void cleanup(void* p);
|
|
||||||
|
|
||||||
private:
|
|
||||||
unsigned int m_slot; //This is a "pseudo-slot", not a native slot
|
|
||||||
|
|
||||||
void init(boost::function1<void, void*>* pcleanup);
|
|
||||||
};
|
|
||||||
|
|
||||||
#if defined(BOOST_HAS_MPTASKS)
|
|
||||||
void thread_cleanup();
|
|
||||||
#endif
|
|
||||||
|
|
||||||
template <typename T>
|
|
||||||
struct tss_adapter
|
|
||||||
{
|
|
||||||
template <typename F>
|
|
||||||
tss_adapter(const F& cleanup) : m_cleanup(cleanup) { }
|
|
||||||
void operator()(void* p) { m_cleanup(static_cast<T*>(p)); }
|
|
||||||
boost::function1<void, T*> m_cleanup;
|
|
||||||
};
|
|
||||||
|
|
||||||
} // namespace detail
|
|
||||||
|
|
||||||
template <typename T>
|
|
||||||
class thread_specific_ptr : private noncopyable
|
|
||||||
{
|
|
||||||
public:
|
|
||||||
thread_specific_ptr()
|
|
||||||
: m_tss(new boost::function1<void, void*>(
|
|
||||||
boost::detail::tss_adapter<T>(
|
|
||||||
&thread_specific_ptr<T>::cleanup)))
|
|
||||||
{
|
|
||||||
}
|
|
||||||
thread_specific_ptr(void (*clean)(T*))
|
|
||||||
: m_tss(new boost::function1<void, void*>(
|
|
||||||
boost::detail::tss_adapter<T>(clean)))
|
|
||||||
{
|
|
||||||
}
|
|
||||||
~thread_specific_ptr() { reset(); }
|
|
||||||
|
|
||||||
T* get() const { return static_cast<T*>(m_tss.get()); }
|
|
||||||
T* operator->() const { return get(); }
|
|
||||||
T& operator*() const { return *get(); }
|
|
||||||
T* release() { T* temp = get(); if (temp) m_tss.set(0); return temp; }
|
|
||||||
void reset(T* p=0)
|
|
||||||
{
|
|
||||||
T* cur = get();
|
|
||||||
if (cur == p) return;
|
|
||||||
m_tss.set(p);
|
|
||||||
if (cur) m_tss.cleanup(cur);
|
|
||||||
}
|
|
||||||
|
|
||||||
private:
|
|
||||||
static void cleanup(T* p) { delete p; }
|
|
||||||
detail::tss m_tss;
|
|
||||||
};
|
|
||||||
|
|
||||||
} // namespace boost
|
|
||||||
|
|
||||||
#endif //BOOST_TSS_WEK070601_HPP
|
|
||||||
|
|
||||||
// Change Log:
|
|
||||||
// 6 Jun 01
|
|
||||||
// WEKEMPF Initial version.
|
|
||||||
// 30 May 02 WEKEMPF
|
|
||||||
// Added interface to set specific cleanup handlers.
|
|
||||||
// Removed TLS slot limits from most implementations.
|
|
||||||
// 22 Mar 04 GlassfordM for WEKEMPF
|
|
||||||
// Fixed: thread_specific_ptr::reset() doesn't check error returned
|
|
||||||
// by tss::set(); tss::set() now throws if it fails.
|
|
||||||
// Fixed: calling thread_specific_ptr::reset() or
|
|
||||||
// thread_specific_ptr::release() causes double-delete: once on
|
|
||||||
// reset()/release() and once on ~thread_specific_ptr().
|
|
||||||
@@ -1,59 +0,0 @@
|
|||||||
// 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_XTIME_WEK070601_HPP
|
|
||||||
#define BOOST_XTIME_WEK070601_HPP
|
|
||||||
|
|
||||||
#include <boost/thread/detail/config.hpp>
|
|
||||||
|
|
||||||
#include <boost/cstdint.hpp>
|
|
||||||
|
|
||||||
namespace boost {
|
|
||||||
|
|
||||||
enum xtime_clock_types
|
|
||||||
{
|
|
||||||
TIME_UTC=1
|
|
||||||
// TIME_TAI,
|
|
||||||
// TIME_MONOTONIC,
|
|
||||||
// TIME_PROCESS,
|
|
||||||
// TIME_THREAD,
|
|
||||||
// TIME_LOCAL,
|
|
||||||
// TIME_SYNC,
|
|
||||||
// TIME_RESOLUTION
|
|
||||||
};
|
|
||||||
|
|
||||||
struct xtime
|
|
||||||
{
|
|
||||||
#if defined(BOOST_NO_INT64_T)
|
|
||||||
typedef int_fast32_t xtime_sec_t; //INT_FAST32_MIN <= sec <= INT_FAST32_MAX
|
|
||||||
#else
|
|
||||||
typedef int_fast64_t xtime_sec_t; //INT_FAST64_MIN <= sec <= INT_FAST64_MAX
|
|
||||||
#endif
|
|
||||||
|
|
||||||
typedef int_fast32_t xtime_nsec_t; //0 <= xtime.nsec < NANOSECONDS_PER_SECOND
|
|
||||||
|
|
||||||
xtime_sec_t sec;
|
|
||||||
xtime_nsec_t nsec;
|
|
||||||
};
|
|
||||||
|
|
||||||
int BOOST_THREAD_DECL xtime_get(struct xtime* xtp, int clock_type);
|
|
||||||
|
|
||||||
inline int xtime_cmp(const xtime& xt1, const xtime& xt2)
|
|
||||||
{
|
|
||||||
if (xt1.sec == xt2.sec)
|
|
||||||
return (int)(xt1.nsec - xt2.nsec);
|
|
||||||
else
|
|
||||||
return (xt1.sec > xt2.sec) ? 1 : -1;
|
|
||||||
}
|
|
||||||
|
|
||||||
} // namespace boost
|
|
||||||
|
|
||||||
#endif //BOOST_XTIME_WEK070601_HPP
|
|
||||||
Reference in New Issue
Block a user