commit f585d38fa3f36eda11687abebafc09db67fa3042 Author: Beman Dawes Date: Fri Jun 15 15:27:08 2001 +0000 Initial commit [SVN r10338] diff --git a/.gitattributes b/.gitattributes new file mode 100644 index 00000000..3e84d7c7 --- /dev/null +++ b/.gitattributes @@ -0,0 +1,96 @@ +* text=auto !eol svneol=native#text/plain +*.gitattributes text svneol=native#text/plain + +# Scriptish formats +*.bat text svneol=native#text/plain +*.bsh text svneol=native#text/x-beanshell +*.cgi text svneol=native#text/plain +*.cmd text svneol=native#text/plain +*.js text svneol=native#text/javascript +*.php text svneol=native#text/x-php +*.pl text svneol=native#text/x-perl +*.pm text svneol=native#text/x-perl +*.py text svneol=native#text/x-python +*.sh eol=lf svneol=LF#text/x-sh +configure eol=lf svneol=LF#text/x-sh + +# Image formats +*.bmp binary svneol=unset#image/bmp +*.gif binary svneol=unset#image/gif +*.ico binary svneol=unset#image/ico +*.jpeg binary svneol=unset#image/jpeg +*.jpg binary svneol=unset#image/jpeg +*.png binary svneol=unset#image/png +*.tif binary svneol=unset#image/tiff +*.tiff binary svneol=unset#image/tiff +*.svg text svneol=native#image/svg%2Bxml + +# Data formats +*.pdf binary svneol=unset#application/pdf +*.avi binary svneol=unset#video/avi +*.doc binary svneol=unset#application/msword +*.dsp text svneol=crlf#text/plain +*.dsw text svneol=crlf#text/plain +*.eps binary svneol=unset#application/postscript +*.gz binary svneol=unset#application/gzip +*.mov binary svneol=unset#video/quicktime +*.mp3 binary svneol=unset#audio/mpeg +*.ppt binary svneol=unset#application/vnd.ms-powerpoint +*.ps binary svneol=unset#application/postscript +*.psd binary svneol=unset#application/photoshop +*.rdf binary svneol=unset#text/rdf +*.rss text svneol=unset#text/xml +*.rtf binary svneol=unset#text/rtf +*.sln text svneol=native#text/plain +*.swf binary svneol=unset#application/x-shockwave-flash +*.tgz binary svneol=unset#application/gzip +*.vcproj text svneol=native#text/xml +*.vcxproj text svneol=native#text/xml +*.vsprops text svneol=native#text/xml +*.wav binary svneol=unset#audio/wav +*.xls binary svneol=unset#application/vnd.ms-excel +*.zip binary svneol=unset#application/zip + +# Text formats +.htaccess text svneol=native#text/plain +*.bbk text svneol=native#text/xml +*.cmake text svneol=native#text/plain +*.css text svneol=native#text/css +*.dtd text svneol=native#text/xml +*.htm text svneol=native#text/html +*.html text svneol=native#text/html +*.ini text svneol=native#text/plain +*.log text svneol=native#text/plain +*.mak text svneol=native#text/plain +*.qbk text svneol=native#text/plain +*.rst text svneol=native#text/plain +*.sql text svneol=native#text/x-sql +*.txt text svneol=native#text/plain +*.xhtml text svneol=native#text/xhtml%2Bxml +*.xml text svneol=native#text/xml +*.xsd text svneol=native#text/xml +*.xsl text svneol=native#text/xml +*.xslt text svneol=native#text/xml +*.xul text svneol=native#text/xul +*.yml text svneol=native#text/plain +boost-no-inspect text svneol=native#text/plain +CHANGES text svneol=native#text/plain +COPYING text svneol=native#text/plain +INSTALL text svneol=native#text/plain +Jamfile text svneol=native#text/plain +Jamroot text svneol=native#text/plain +Jamfile.v2 text svneol=native#text/plain +Jamrules text svneol=native#text/plain +Makefile* text svneol=native#text/plain +README text svneol=native#text/plain +TODO text svneol=native#text/plain + +# Code formats +*.c text svneol=native#text/plain +*.cpp text svneol=native#text/plain +*.h text svneol=native#text/plain +*.hpp text svneol=native#text/plain +*.ipp text svneol=native#text/plain +*.tpp text svneol=native#text/plain +*.jam text svneol=native#text/plain +*.java text svneol=native#text/plain diff --git a/include/boost/thread/_atomic.hpp b/include/boost/thread/_atomic.hpp new file mode 100644 index 00000000..463f8f61 --- /dev/null +++ b/include/boost/thread/_atomic.hpp @@ -0,0 +1,61 @@ +/* + * + * Copyright (C) 2001 + * 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. + * + * Revision History (excluding minor changes for specific compilers) + * 8 Feb 01 Initial version. + */ + +#ifndef BOOST_ATOMIC_HPP +#define BOOST_ATOMIC_HPP + +#include +#ifndef BOOST_HAS_THREADS +# error Thread support is unavailable! +#endif + +#if !defined(BOOST_HAS_WINTHREADS) +# include +#endif + +namespace boost { + class atomic_t + { + public: + typedef long value_type; + + friend value_type read(const atomic_t&); + friend value_type increment(atomic_t&); + friend value_type decrement(atomic_t&); + friend value_type swap(atomic_t&, value_type); + friend value_type compare_swap(atomic_t&, value_type, value_type); + + explicit atomic_t(value_type val=0) + : _value(val) + { + } + + private: + volatile value_type _value; +#if !defined(BOOST_HAS_WINTHREADS) + mutex _mutex; +#endif + }; + + extern atomic_t::value_type read(const atomic_t&); + extern atomic_t::value_type increment(atomic_t&); + extern atomic_t::value_type decrement(atomic_t&); + extern atomic_t::value_type swap(atomic_t&, atomic_t::value_type); + extern atomic_t::value_type compare_swap(atomic_t&, atomic_t::value_type, atomic_t::value_type); +} // namespace boost + +#endif // BOOST_ATOMIC_HPP diff --git a/include/boost/thread/condition.hpp b/include/boost/thread/condition.hpp new file mode 100644 index 00000000..38e4f7a5 --- /dev/null +++ b/include/boost/thread/condition.hpp @@ -0,0 +1,156 @@ +/* + * + * Copyright (C) 2001 + * 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. + * + * Revision History (excluding minor changes for specific compilers) + * 8 Feb 01 Initial version. + * 22 May 01 Modified to use xtime for time outs. + * 23 May 01 Removed "duration" timed_waits, as they are too difficult + * to use with spurious wakeups. + */ + +#ifndef BOOST_CONDITION_HPP +#define BOOST_CONDITION_HPP + +#include +#ifndef BOOST_HAS_THREADS +# error Thread support is unavailable! +#endif + +#include +#include + +#if defined(BOOST_HAS_PTHREADS) +# include +#endif + +namespace boost +{ + class condition : private noncopyable + { + public: + condition(); + ~condition(); + + void notify_one(); + void notify_all(); + + template + void wait(L& lock) + { + if (!lock) + throw lock_error(); + + do_wait(lock._mutex); + } + + template + void wait(L& lock, Pr pred) + { + if (!lock) + throw lock_error(); + + while (!pred()) + do_wait(lock._mutex); + } + + template + bool timed_wait(L& lock, const xtime& xt) + { + if (!lock) + throw lock_error(); + + return do_timed_wait(lock._mutex, xt); + } + + template + bool timed_wait(L& lock, const xtime& xt, Pr pred) + { + if (!lock) + throw lock_error(); + + while (!pred()) + { + if (!do_timed_wait(lock._mutex, xt)) + return false; + } + + return true; + } + + private: + template + void do_wait(M& mutex) + { +#if defined(BOOST_HAS_WINTHREADS) + enter_wait(); +#endif + + typename M::cv_state state; + mutex.do_unlock(state); + +#if defined(BOOST_HAS_PTHREADS) + do_wait(state.pmutex); +#elif defined(BOOST_HAS_WINTHREADS) + do_wait(); +#endif + + mutex.do_lock(state); + } + + template + bool do_timed_wait(M& mutex, const xtime& xt) + { +#if defined(BOOST_HAS_WINTHREADS) + enter_wait(); +#endif + + typename M::cv_state state; + mutex.do_unlock(state); + + bool ret = false; + +#if defined(BOOST_HAS_PTHREADS) + ret = do_timed_wait(xt, state.pmutex); +#elif defined(BOOST_HAS_WINTHREADS) + ret = do_timed_wait(xt); +#endif + + mutex.do_lock(state); + + return ret; + } + +#if defined(BOOST_HAS_WINTHREADS) + 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) + unsigned long _gate; + unsigned long _queue; + unsigned long _mutex; + unsigned _gone; // # threads that timed out and never made it to the _queue + long _blocked; // # threads _blocked _waiting for the condition + unsigned _waiting; // # threads _waiting no longer _waiting for the condition but still + // _waiting to be removed from the _queue +#elif defined(BOOST_HAS_PTHREADS) + pthread_cond_t _cond; +#endif + }; +} // namespace boost + +#endif // BOOST_CONDITION_HPP diff --git a/include/boost/thread/config.hpp b/include/boost/thread/config.hpp new file mode 100644 index 00000000..fe82f424 --- /dev/null +++ b/include/boost/thread/config.hpp @@ -0,0 +1,65 @@ +// This file is used to configure Boost.Threads during development +// in order to decouple dependency on any Boost release. Once +// accepted into Boost these contents will be moved to +// or some other appropriate build configuration and all +// #include statements will be changed +// accordingly. + +#ifndef BOOST_THREAD_CONFIG_HPP +#define BOOST_THREAD_CONFIG_HPP + +#include + +// Define if threading support is enabled for the toolset. +#undef BOOST_HAS_THREADS + +// Define if threading should be implemented in terms of Win32 threads. +#undef BOOST_HAS_WINTHREADS + +// Define if threading should be implemented in terms of POSIX threads. +#undef BOOST_HAS_PTHREADS + +// Define if BOOST_HAS_PTHREADS and pthread_delay_np() exists. +#undef BOOST_HAS_PTHREAD_DELAY_NP + +// Define if BOOST_HAS_PTHREADS and not BOOST_HAS_PTHREAD_DELAY_NP +// but nanosleep can be used instead. +#undef BOOST_HAS_NANOSLEEP + +// Define if BOOST_HAS_PTHREADS and pthread_yield() exists. +#undef BOOST_HAS_PTHREAD_YIELD + +// Define if BOOST_HAS_PTHREADS and not BOOST_HAS_PTHREAD_YIELD and +// sched_yield() exists. +#undef BOOST_HAS_SCHED_YIELD + +// Define if gettimeofday() exists. +#undef BOOST_HAS_GETTIMEOFDAY + +// Define if not BOOST_HAS_GETTIMEOFDAY and clock_gettime() exists. +#undef BOOST_HAS_CLOCK_GETTIME + +// Define if not BOOST_HAS_GETTIMEOFDAY and not BOOST_HAS_CLOCK_GETTIME and +// GetSystemTimeAsFileTime() can be called with an FTIME structure. +#undef BOOST_HAS_FTIME + +// Define if pthread_mutexattr_settype and pthread_mutexattr_gettype exist. +#undef BOOST_HAS_PTHREAD_MUTEXATTR_SETTYPE + +// Here we'll set up known compiler options. + +#if defined(BOOST_MSVC) +# if defined(_MT) +# define BOOST_HAS_THREADS +# endif +//# define BOOST_HAS_WINTHREADS // comment out this to test pthreads-win32. +# if !defined(BOOST_HAS_WINTHREADS) +# define BOOST_HAS_PTHREADS +# define BOOST_HAS_PTHREAD_MUTEXATTR_SETTYPE +# define PtW32NoCatchWarn +# pragma comment(lib, "pthreadVCE.lib") +# endif +# define BOOST_HAS_FTIME +#endif + +#endif \ No newline at end of file diff --git a/include/boost/thread/mutex.hpp b/include/boost/thread/mutex.hpp new file mode 100644 index 00000000..7e9d3ece --- /dev/null +++ b/include/boost/thread/mutex.hpp @@ -0,0 +1,147 @@ +/* + * Copyright (C) 2001 + * 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. + * + * Revision History (excluding minor changes for specific compilers) + * 8 Feb 01 Initial version. + * 22 May 01 Modified to use xtime for time outs. Factored out + * to three classes, mutex, try_mutex and timed_mutex. + */ + +#ifndef BOOST_MUTEX_HPP +#define BOOST_MUTEX_HPP + +#include +#ifndef BOOST_HAS_THREADS +# error Thread support is unavailable! +#endif + +#include +#include +#include + +#if defined(BOOST_HAS_PTHREADS) +# include +#endif + +namespace boost +{ + class condition; + + class mutex : private noncopyable + { + public: + friend class basic_lock; + friend class condition; + + typedef basic_lock 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; + }; +#endif + void do_lock(); + void do_unlock(); + void do_lock(cv_state& state); + void do_unlock(cv_state& state); + +#if defined(BOOST_HAS_WINTHREADS) + unsigned long _mutex; +#elif defined(BOOST_HAS_PTHREADS) + pthread_mutex_t _mutex; +#endif + }; + + class try_mutex : private noncopyable + { + public: + friend class basic_lock; + friend class basic_trylock; + friend class condition; + + typedef basic_lock lock; + typedef basic_trylock trylock; + + 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; + }; +#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) + unsigned long _mutex; +#elif defined(BOOST_HAS_PTHREADS) + pthread_mutex_t _mutex; +#endif + }; + + class timed_mutex : private noncopyable + { + public: + friend class basic_lock; + friend class basic_trylock; + friend class basic_timedlock; + friend class condition; + + typedef basic_lock lock; + typedef basic_trylock trylock; + typedef basic_timedlock timedlock; + + 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; + }; +#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) + unsigned long _mutex; +#elif defined(BOOST_HAS_PTHREADS) + pthread_mutex_t _mutex; + pthread_cond_t _cond; + bool _locked; +#endif + }; +} // namespace boost + +#endif // BOOST_MUTEX_HPP diff --git a/include/boost/thread/recursive_mutex.hpp b/include/boost/thread/recursive_mutex.hpp new file mode 100644 index 00000000..f44bf131 --- /dev/null +++ b/include/boost/thread/recursive_mutex.hpp @@ -0,0 +1,167 @@ +/* + * Copyright (C) 2001 + * 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. + * + * Revision History (excluding minor changes for specific compilers) + * 8 Feb 01 Initial version. + * 1 Jun 01 Modified to use xtime for time outs. Factored out + * to three classes, mutex, try_mutex and timed_mutex. + * 11 Jun 01 Modified to use PTHREAD_MUTEX_RECURSIVE if available. + */ + +#ifndef BOOST_RECURSIVE_MUTEX_HPP +#define BOOST_RECURSIVE_MUTEX_HPP + +#include +#ifndef BOOST_HAS_THREADS +# error Thread support is unavailable! +#endif + +#include +#include + +#if defined(BOOST_HAS_PTHREADS) +# include +#endif + +namespace boost +{ + class condition; + + class recursive_mutex : private noncopyable + { + public: + friend class basic_lock; + friend class condition; + + typedef basic_lock lock; + + recursive_mutex(); + ~recursive_mutex(); + + private: +#if defined(BOOST_HAS_WINTHREADS) + typedef 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) + unsigned long _mutex; + unsigned long _count; +#elif defined(BOOST_HAS_PTHREADS) + pthread_mutex_t _mutex; + unsigned _count; +# if !defined(BOOST_HAS_PTHREAD_MUTEXATTR_SETTYPE) + pthread_cond_t _unlocked; + pthread_t _thread_id; + bool _valid_id; +# endif +#endif + }; + + class recursive_try_mutex : private noncopyable + { + public: + friend class basic_lock; + friend class basic_trylock; + friend class condition; + + typedef basic_lock lock; + typedef basic_trylock trylock; + + recursive_try_mutex(); + ~recursive_try_mutex(); + + private: +#if defined(BOOST_HAS_WINTHREADS) + typedef 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) + unsigned long _mutex; + unsigned long _count; +#elif defined(BOOST_HAS_PTHREADS) + pthread_mutex_t _mutex; + unsigned _count; +# if !defined(BOOST_HAS_PTHREAD_MUTEXATTR_SETTYPE) + pthread_cond_t _unlocked; + pthread_t _thread_id; + bool _valid_id; +# endif +#endif + }; + + class recursive_timed_mutex : private noncopyable + { + public: + friend class basic_lock; + friend class basic_trylock; + friend class basic_timedlock; + friend class condition; + + typedef basic_lock lock; + typedef basic_trylock trylock; + typedef basic_timedlock timedlock; + + recursive_timed_mutex(); + ~recursive_timed_mutex(); + + private: +#if defined(BOOST_HAS_WINTHREADS) + typedef 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) + unsigned long _mutex; + unsigned long _count; +#elif defined(BOOST_HAS_PTHREADS) + pthread_mutex_t _mutex; + pthread_cond_t _unlocked; + pthread_t _thread_id; + bool _valid_id; + unsigned _count; +#endif + }; +} // namespace boost + +#endif // BOOST_RECURSIVE_MUTEX_HPP diff --git a/include/boost/thread/semaphore.hpp b/include/boost/thread/semaphore.hpp new file mode 100644 index 00000000..773e6e8a --- /dev/null +++ b/include/boost/thread/semaphore.hpp @@ -0,0 +1,57 @@ +/* + * + * Copyright (C) 2001 + * 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. + * + * Revision History (excluding minor changes for specific compilers) + * 8 Feb 01 Initial version. + * 22 May 01 Modified to use xtime for time outs. + */ + +#ifndef BOOST_SEMAPHORE_HPP +#define BOOST_SEMAPHORE_HPP + +#include +#ifndef BOOST_HAS_THREADS +# error Thread support is unavailable! +#endif + +#include +#include + +#if defined(BOOST_HAS_PTHREADS) +# include +#endif + +namespace boost { + class semaphore : private noncopyable + { + public: + explicit semaphore(unsigned count=0, unsigned max=0); + ~semaphore(); + + bool up(unsigned count=1, unsigned* prev=0); + void down(); + bool down(const xtime& xt); + + private: +#if defined(BOOST_HAS_WINTHREADS) + unsigned long _sema; +#elif defined(BOOST_HAS_PTHREADS) + pthread_mutex_t _mutex; + pthread_cond_t _cond; + unsigned _available; + unsigned _max; +#endif + }; +} // namespace boost + +#endif // BOOST_SEMAPHORE_HPP diff --git a/include/boost/thread/thread.hpp b/include/boost/thread/thread.hpp new file mode 100644 index 00000000..9920c073 --- /dev/null +++ b/include/boost/thread/thread.hpp @@ -0,0 +1,88 @@ +/* + * Copyright (C) 2001 + * 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. + * + * Revision History (excluding minor changes for specific compilers) + * 8 Feb 01 Initial version. + * 1 Jun 01 Added boost::thread initial implementation. + */ + +#ifndef BOOST_THREAD_HPP +#define BOOST_THREAD_HPP + +#include +#ifndef BOOST_HAS_THREADS +# error Thread support is unavailable! +#endif + +#include +#include +#include + +#if defined(BOOST_HAS_PTHREADS) + struct timespec; +#endif + +namespace boost +{ + namespace detail + { + class thread_state; +// typedef function threadfunc; + typedef void (*threadfunc)(void* param); + } + + class lock_error : public std::runtime_error + { + public: + lock_error(); + }; + + class thread + { + public: + thread() : _state(0) { } + thread(const thread& other); + ~thread(); + + thread& operator=(const thread& other) + { + thread temp(other); + swap(temp); + return *this; + } + thread& swap(thread& other) + { + detail::thread_state* temp = other._state; + other._state = _state; + _state = temp; + return *this; + } + + bool operator==(const thread& other) { return _state == other._state; } + bool operator!=(const thread& other) { return _state != other._state; } + + bool is_alive() const; + void join(); + + static thread create(const detail::threadfunc& func, void* param=0); + static thread self(); + + static void join_all(); + static void sleep(const xtime& xt); + static void yield(); + + private: + detail::thread_state* _state; + }; +} // namespace boost + +#endif // BOOST_THREAD_HPP diff --git a/include/boost/thread/tss.hpp b/include/boost/thread/tss.hpp new file mode 100644 index 00000000..a6c00370 --- /dev/null +++ b/include/boost/thread/tss.hpp @@ -0,0 +1,49 @@ +/* + * Copyright (C) 2001 + * 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. + * + * Revision History (excluding minor changes for specific compilers) + * 6 Jun 01 Initial version. + */ + +#ifndef BOOST_TSS_HPP +#define BOOST_TSS_HPP + +#include +#ifndef BOOST_HAS_THREADS +# error Thread support is unavailable! +#endif + +#if defined(BOOST_HAS_PTHREADS) +# include +#endif + +namespace boost +{ + class tss + { + public: + tss(); + ~tss(); + + void* get() const; + bool set(void* value); + + private: +#if defined(BOOST_HAS_WINTHREADS) + unsigned long _key; +#elif defined(BOOST_HAS_PTHREADS) + pthread_key_t _key; +#endif + }; +} + +#endif // BOOST_TSS_HPP \ No newline at end of file diff --git a/include/boost/thread/xlock.hpp b/include/boost/thread/xlock.hpp new file mode 100644 index 00000000..d97a82b7 --- /dev/null +++ b/include/boost/thread/xlock.hpp @@ -0,0 +1,163 @@ +/* + * Copyright (C) 2001 + * 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. + * + * Revision History (excluding minor changes for specific compilers) + * 8 Feb 01 Initial version. + * 22 May 01 Modified to use xtime for time outs. + */ + +#ifndef BOOST_XLOCK_HPP +#define BOOST_XLOCK_HPP + +#include +#include +#include + +namespace boost { + class condition; + + template + class basic_lock : noncopyable + { + public: + friend class condition; + + typedef M mutex_type; + + explicit basic_lock(M& mx, bool lock_it=true) + : _mutex(mx), _locked(false) + { + if (lock_it) lock(); + } + ~basic_lock() + { + if (_locked) unlock(); + } + + void lock() + { + if (_locked) throw lock_error(); + _mutex.do_lock(); + _locked = true; + } + void unlock() + { + if (!_locked) throw lock_error(); + _mutex.do_unlock(); + _locked = false; + } + + operator const void*() const { return _locked ? this : 0; } + + private: + M& _mutex; + bool _locked; + }; + + template + class basic_trylock : private noncopyable + { + public: + friend class condition; + + typedef M mutex_type; + + explicit basic_trylock(M& mx) + : _mutex(mx), _locked(false) + { + try_lock(); + } + basic_trylock(M& mx, bool lock_it) + : _mutex(mx), _locked(false) + { + if (lock_it) lock(); + } + ~basic_trylock() + { + if (_locked) unlock(); + } + + void lock() + { + if (_locked) throw lock_error(); + _mutex.do_lock(); + _locked = true; + } + bool try_lock() + { + if (_locked) throw lock_error(); + return (_locked = _mutex.do_trylock()); + } + void unlock() + { + if (!_locked) throw lock_error(); + _mutex.do_unlock(); + _locked = false; + } + + operator const void*() const { return _locked ? this : 0; } + + private: + M& _mutex; + bool _locked; + }; + + template + class basic_timedlock : private noncopyable + { + public: + friend class condition; + + typedef M mutex_type; + + basic_timedlock(M& mx, const xtime& xt) + : _mutex(mx), _locked(false) + { + timed_lock(xt); + } + basic_timedlock(M& mx, bool lock_it) + : _mutex(mx), _locked(false) + { + if (lock_it) lock(); + } + ~basic_timedlock() + { + if (_locked) unlock(); + } + + void lock() + { + if (_locked) throw lock_error(); + _mutex.do_lock(); + _locked = true; + } + bool timed_lock(const xtime& xt) + { + if (_locked) throw lock_error(); + return (_locked = _mutex.do_timedlock(xt)); + } + void unlock() + { + if (!_locked) throw lock_error(); + _mutex.do_unlock(); + _locked = false; + } + + operator const void*() const { return _locked ? this : 0; } + + private: + M& _mutex; + bool _locked; + }; +} // namespace boost + +#endif // BOOST_XLOCK_HPP diff --git a/include/boost/thread/xtime.hpp b/include/boost/thread/xtime.hpp new file mode 100644 index 00000000..b323640a --- /dev/null +++ b/include/boost/thread/xtime.hpp @@ -0,0 +1,49 @@ +/* + * Copyright (C) 2001 + * 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. + * + * Revision History (excluding minor changes for specific compilers) + * 8 Feb 01 Initial version. + */ + +#ifndef BOOST_XTIME_HPP +#define BOOST_XTIME_HPP + +#include + +namespace boost +{ + enum + { + 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) + int_fast32_t sec; +#else + int_fast64_t sec; +#endif + int_fast32_t nsec; + }; + + int xtime_get(struct xtime* xtp, int clock_type); +} + +#endif // BOOST_XTIME_HPP \ No newline at end of file