2
0
mirror of https://github.com/boostorg/thread.git synced 2026-02-03 09:42:16 +00:00

Compare commits

...

10 Commits

Author SHA1 Message Date
Beman Dawes
560e8320d1 Branch for development of boost.system related changes
[SVN r40931]
2007-11-08 14:20:16 +00:00
Anthony Williams
5de1582a0a Added missing licence and copyright
[SVN r40884]
2007-11-07 12:10:17 +00:00
Anthony Williams
39c864e31f use condition so we know when threads have unblocked, to avoid hard-coding a delay
[SVN r40846]
2007-11-06 17:15:50 +00:00
Anthony Williams
320cb63df4 Use BOOST_VERIFY instead of BOOST_ASSERT in many places in order to avoid unused variable warnings
[SVN r40792]
2007-11-05 16:47:25 +00:00
Roland Schwarz
c246222ded Cosmetic change to please gcc.
[SVN r40791]
2007-11-05 16:22:17 +00:00
Roland Schwarz
b7edb2873c Usage requirements added.
[SVN r40790]
2007-11-05 16:12:49 +00:00
Anthony Williams
89f2032c0d Use pthread_equal for comparing pthread_t IDs; use BOOST_VERIFY instead of BOOST_ASSERT in many places in order to avoid unused variable warnings
[SVN r40787]
2007-11-05 14:16:21 +00:00
Anthony Williams
d2f8230093 threadapi is a composite feature again
[SVN r40774]
2007-11-05 10:15:24 +00:00
Roland Schwarz
9f6b5d169a Get rid of "unsused variable" warnings by making use of BOOST_VERIFY.
This changeset is for pthread only.


[SVN r40742]
2007-11-04 17:17:01 +00:00
Anthony Williams
e56708d4aa added missing include
[SVN r40730]
2007-11-03 22:00:12 +00:00
21 changed files with 260 additions and 226 deletions

View File

@@ -75,6 +75,84 @@ rule tag ( name : type ? : property-set )
$(result) : $(type) : $(property-set) ] ;
}
rule win32_pthread_paths ( properties * )
{
local result ;
local PTW32_INCLUDE ;
local PTW32_LIB ;
PTW32_INCLUDE = [ modules.peek : PTW32_INCLUDE ] ;
PTW32_LIB = [ modules.peek : PTW32_LIB ] ;
PTW32_INCLUDE ?= [ modules.peek user-config : PTW32_INCLUDE ] ;
PTW32_LIB ?= [ modules.peek user-config : PTW32_LIB ] ;
PTW32_INCLUDE ?= [ modules.peek site-config : PTW32_INCLUDE ] ;
PTW32_LIB ?= [ modules.peek site-config : PTW32_LIB ] ;
if ! ( $(PTW32_INCLUDE) && $(PTW32_LIB) )
{
if ! $(.notified)
{
echo "************************************************************" ;
echo "Trying to build Boost.Thread with pthread support." ;
echo "If you need pthread you should specify the paths." ;
echo "You can specify them in site-config.jam, user-config.jam" ;
echo "or in the environment." ;
echo "For example:" ;
echo "PTW32_INCLUDE=C:\\Program Files\\ptw32\\Pre-built2\\include" ;
echo "PTW32_LIB=C:\\Program Files\\ptw32\\Pre-built2\\lib" ;
echo "************************************************************" ;
.notified = true ;
}
}
else
{
local include_path = [ path.make $(PTW32_INCLUDE) ] ;
local lib_path = [ path.make $(PTW32_LIB) ] ;
local libname = pthread ;
if <toolset>msvc in $(properties)
{
libname = $(libname)VC2.lib ;
}
if <toolset>gcc in $(properties)
{
libname = lib$(libname)GC2.a ;
}
lib_path = [ path.glob $(lib_path) : $(libname) ] ;
if ! $(lib_path)
{
if ! $(.notified)
{
echo "************************************************************" ;
echo "Trying to build Boost.Thread with pthread support." ;
echo "But the library" $(libname) "could not be found in path" ;
echo $(PTW32_LIB) ;
echo "************************************************************" ;
.notified = true ;
}
}
else
{
result += <include>$(include_path) ;
result += <library>$(lib_path) ;
}
}
return $(result) ;
}
rule usage-requirements ( properties * )
{
local result ;
if <threadapi>pthread in $(properties)
{
result += <define>BOOST_THREAD_POSIX ;
if <target-os>windows in $(properties)
{
result += [ win32_pthread_paths $(properties) ] ;
# TODO: What is for static linking? Is the <library> also needed
# in that case?
}
}
return $(result) ;
}
rule requirements ( properties * )
{
@@ -84,62 +162,14 @@ rule requirements ( properties * )
result += <define>BOOST_THREAD_POSIX ;
if <target-os>windows in $(properties)
{
local PTW32_INCLUDE ;
local PTW32_LIB ;
PTW32_INCLUDE = [ modules.peek : PTW32_INCLUDE ] ;
PTW32_LIB = [ modules.peek : PTW32_LIB ] ;
PTW32_INCLUDE ?= [ modules.peek user-config : PTW32_INCLUDE ] ;
PTW32_LIB ?= [ modules.peek user-config : PTW32_LIB ] ;
PTW32_INCLUDE ?= [ modules.peek site-config : PTW32_INCLUDE ] ;
PTW32_LIB ?= [ modules.peek site-config : PTW32_LIB ] ;
if ! ( $(PTW32_INCLUDE) && $(PTW32_LIB) )
local paths = [ win32_pthread_paths $(properties) ] ;
if $(paths)
{
if ! $(.notified)
{
echo "************************************************************" ;
echo "Trying to build Boost.Thread with pthread support." ;
echo "If you need pthread you should specify the paths." ;
echo "You can specify them in site-config.jam, user-config.jam" ;
echo "or in the environment." ;
echo "For example:" ;
echo "PTW32_INCLUDE=C:\\Program Files\\ptw32\\Pre-built2\\include" ;
echo "PTW32_LIB=C:\\Program Files\\ptw32\\Pre-built2\\lib" ;
echo "************************************************************" ;
.notified = true ;
}
result = <build>no ;
result += $(paths) ;
}
else
{
local include_path = [ path.make $(PTW32_INCLUDE) ] ;
local lib_path = [ path.make $(PTW32_LIB) ] ;
result += <include>$(include_path) ;
local libname = pthread ;
if <toolset>msvc in $(properties)
{
libname = $(libname)VC2.lib ;
}
if <toolset>gcc in $(properties)
{
libname = lib$(libname)GC2.a ;
}
lib_path = [ path.glob $(lib_path) : $(libname) ] ;
if ! $(lib_path)
{
if ! $(.notified)
{
echo "************************************************************" ;
echo "Trying to build Boost.Thread with pthread support." ;
echo "But the library" $(libname) "could not be found in path" ;
echo $(PTW32_LIB) ;
echo "************************************************************" ;
.notified = true ;
}
result = <build>no ;
}
result += <library>$(lib_path) ;
result = <build>no ;
}
}
}
@@ -172,4 +202,6 @@ explicit thread_sources ;
lib boost_thread
: thread_sources
: <conditional>@requirements
:
: <conditional>@usage-requirements
;

View File

@@ -1,5 +1,11 @@
#ifndef BOOST_THREAD_CONDITION_HPP
#define BOOST_THREAD_CONDITION_HPP
// (C) Copyright 2007 Anthony Williams
//
// 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)
#include <boost/thread/condition_variable.hpp>
namespace boost

View File

@@ -28,15 +28,13 @@ namespace boost
}
inline condition_variable::~condition_variable()
{
int const res=pthread_cond_destroy(&cond);
BOOST_ASSERT(!res);
BOOST_VERIFY(!pthread_cond_destroy(&cond));
}
inline void condition_variable::wait(unique_lock<mutex>& m)
{
detail::interruption_checker check_for_interruption(&cond);
int const cond_res=pthread_cond_wait(&cond,m.mutex()->native_handle());
BOOST_ASSERT(!cond_res);
BOOST_VERIFY(!pthread_cond_wait(&cond,m.mutex()->native_handle()));
}
inline bool condition_variable::timed_wait(unique_lock<mutex>& m,boost::system_time const& wait_until)
@@ -54,14 +52,12 @@ namespace boost
inline void condition_variable::notify_one()
{
int const res=pthread_cond_signal(&cond);
BOOST_ASSERT(!res);
BOOST_VERIFY(!pthread_cond_signal(&cond));
}
inline void condition_variable::notify_all()
{
int const res=pthread_cond_broadcast(&cond);
BOOST_ASSERT(!res);
BOOST_VERIFY(!pthread_cond_broadcast(&cond));
}
class condition_variable_any
@@ -83,17 +79,14 @@ namespace boost
int const res2=pthread_cond_init(&cond,NULL);
if(res2)
{
int const destroy_res=pthread_mutex_destroy(&internal_mutex);
BOOST_ASSERT(!destroy_res);
BOOST_VERIFY(!pthread_mutex_destroy(&internal_mutex));
throw thread_resource_error();
}
}
~condition_variable_any()
{
int const res=pthread_mutex_destroy(&internal_mutex);
BOOST_ASSERT(!res);
int const res2=pthread_cond_destroy(&cond);
BOOST_ASSERT(!res2);
BOOST_VERIFY(!pthread_mutex_destroy(&internal_mutex));
BOOST_VERIFY(!pthread_cond_destroy(&cond));
}
template<typename lock_type>
@@ -160,15 +153,13 @@ namespace boost
void notify_one()
{
boost::pthread::pthread_mutex_scoped_lock internal_lock(&internal_mutex);
int const res=pthread_cond_signal(&cond);
BOOST_ASSERT(!res);
BOOST_VERIFY(!pthread_cond_signal(&cond));
}
void notify_all()
{
boost::pthread::pthread_mutex_scoped_lock internal_lock(&internal_mutex);
int const res=pthread_cond_broadcast(&cond);
BOOST_ASSERT(!res);
BOOST_VERIFY(!pthread_cond_broadcast(&cond));
}
};

View File

@@ -42,20 +42,17 @@ namespace boost
}
~mutex()
{
int const res=pthread_mutex_destroy(&m);
BOOST_ASSERT(!res);
BOOST_VERIFY(!pthread_mutex_destroy(&m));
}
void lock()
{
int const res=pthread_mutex_lock(&m);
BOOST_ASSERT(!res);
BOOST_VERIFY(!pthread_mutex_lock(&m));
}
void unlock()
{
int const res=pthread_mutex_unlock(&m);
BOOST_ASSERT(!res);
BOOST_VERIFY(!pthread_mutex_unlock(&m));
}
bool try_lock()
@@ -98,8 +95,7 @@ namespace boost
int const res2=pthread_cond_init(&cond,NULL);
if(res2)
{
int const destroy_res=pthread_mutex_destroy(&m);
BOOST_ASSERT(!destroy_res);
BOOST_VERIFY(!pthread_mutex_destroy(&m));
throw thread_resource_error();
}
is_locked=false;
@@ -107,11 +103,9 @@ namespace boost
}
~timed_mutex()
{
int const res=pthread_mutex_destroy(&m);
BOOST_ASSERT(!res);
BOOST_VERIFY(!pthread_mutex_destroy(&m));
#ifndef BOOST_PTHREAD_HAS_TIMEDLOCK
int const res2=pthread_cond_destroy(&cond);
BOOST_ASSERT(!res2);
BOOST_VERIFY(!pthread_cond_destroy(&cond));
#endif
}
@@ -124,14 +118,12 @@ namespace boost
#ifdef BOOST_PTHREAD_HAS_TIMEDLOCK
void lock()
{
int const res=pthread_mutex_lock(&m);
BOOST_ASSERT(!res);
BOOST_VERIFY(!pthread_mutex_lock(&m));
}
void unlock()
{
int const res=pthread_mutex_unlock(&m);
BOOST_ASSERT(!res);
BOOST_VERIFY(!pthread_mutex_unlock(&m));
}
bool try_lock()
@@ -153,8 +145,7 @@ namespace boost
boost::pthread::pthread_mutex_scoped_lock const local_lock(&m);
while(is_locked)
{
int const cond_res=pthread_cond_wait(&cond,&m);
BOOST_ASSERT(!cond_res);
BOOST_VERIFY(!pthread_cond_wait(&cond,&m));
}
is_locked=true;
}
@@ -163,8 +154,7 @@ namespace boost
{
boost::pthread::pthread_mutex_scoped_lock const local_lock(&m);
is_locked=false;
int const res=pthread_cond_signal(&cond);
BOOST_ASSERT(!res);
BOOST_VERIFY(!pthread_cond_signal(&cond));
}
bool try_lock()

View File

@@ -13,47 +13,28 @@
#include <pthread.h>
#include <boost/assert.hpp>
#include "pthread_mutex_scoped_lock.hpp"
namespace boost {
struct once_flag
{
pthread_mutex_t mutex;
unsigned flag;
unsigned long flag;
};
#define BOOST_ONCE_INIT {PTHREAD_MUTEX_INITIALIZER,0}
namespace detail
{
struct pthread_mutex_scoped_lock
{
pthread_mutex_t * mutex;
explicit pthread_mutex_scoped_lock(pthread_mutex_t* mutex_):
mutex(mutex_)
{
int const res=pthread_mutex_lock(mutex);
BOOST_ASSERT(!res);
}
~pthread_mutex_scoped_lock()
{
int const res=pthread_mutex_unlock(mutex);
BOOST_ASSERT(!res);
}
};
}
template<typename Function>
void call_once(once_flag& flag,Function f)
{
long const function_complete_flag_value=0xc15730e2;
unsigned long const function_complete_flag_value=0xc15730e2ul;
#ifdef BOOST_PTHREAD_HAS_ATOMICS
if(::boost::detail::interlocked_read_acquire(&flag.flag)!=function_complete_flag_value)
{
#endif
detail::pthread_mutex_scoped_lock const lock(&flag.mutex);
pthread::pthread_mutex_scoped_lock const lock(&flag.mutex);
if(flag.flag!=function_complete_flag_value)
{
f();

View File

@@ -1,5 +1,11 @@
#ifndef BOOST_PTHREAD_MUTEX_SCOPED_LOCK_HPP
#define BOOST_PTHREAD_MUTEX_SCOPED_LOCK_HPP
// (C) Copyright 2007 Anthony Williams
//
// 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)
#include <pthread.h>
#include <boost/assert.hpp>
@@ -14,13 +20,11 @@ namespace boost
explicit pthread_mutex_scoped_lock(pthread_mutex_t* m_):
m(m_)
{
int const res=pthread_mutex_lock(m);
BOOST_ASSERT(!res);
BOOST_VERIFY(!pthread_mutex_lock(m));
}
~pthread_mutex_scoped_lock()
{
int const res=pthread_mutex_unlock(m);
BOOST_ASSERT(!res);
BOOST_VERIFY(!pthread_mutex_unlock(m));
}
};

View File

@@ -53,25 +53,21 @@ namespace boost
{
throw thread_resource_error();
}
int const destroy_attr_res=pthread_mutexattr_destroy(&attr);
BOOST_ASSERT(!destroy_attr_res);
BOOST_VERIFY(!pthread_mutexattr_destroy(&attr));
}
~recursive_mutex()
{
int const res=pthread_mutex_destroy(&m);
BOOST_ASSERT(!res);
BOOST_VERIFY(!pthread_mutex_destroy(&m));
}
void lock()
{
int const res=pthread_mutex_lock(&m);
BOOST_ASSERT(!res);
BOOST_VERIFY(!pthread_mutex_lock(&m));
}
void unlock()
{
int const res=pthread_mutex_unlock(&m);
BOOST_ASSERT(!res);
BOOST_VERIFY(!pthread_mutex_unlock(&m));
}
bool try_lock()
@@ -117,12 +113,10 @@ namespace boost
int const res=pthread_mutex_init(&m,&attr);
if(res)
{
int const destroy_attr_res=pthread_mutexattr_destroy(&attr);
BOOST_ASSERT(!destroy_attr_res);
BOOST_VERIFY(!pthread_mutexattr_destroy(&attr));
throw thread_resource_error();
}
int const destroy_attr_res=pthread_mutexattr_destroy(&attr);
BOOST_ASSERT(!destroy_attr_res);
BOOST_VERIFY(!pthread_mutexattr_destroy(&attr));
#else
int const res=pthread_mutex_init(&m,NULL);
if(res)
@@ -132,8 +126,7 @@ namespace boost
int const res2=pthread_cond_init(&cond,NULL);
if(res2)
{
int const destroy_res=pthread_mutex_destroy(&m);
BOOST_ASSERT(!destroy_res);
BOOST_VERIFY(!pthread_mutex_destroy(&m));
throw thread_resource_error();
}
is_locked=false;
@@ -142,11 +135,9 @@ namespace boost
}
~recursive_timed_mutex()
{
int const res=pthread_mutex_destroy(&m);
BOOST_ASSERT(!res);
BOOST_VERIFY(!pthread_mutex_destroy(&m));
#ifndef BOOST_PTHREAD_HAS_TIMEDLOCK
int const res2=pthread_cond_destroy(&cond);
BOOST_ASSERT(!res2);
BOOST_VERIFY(!pthread_cond_destroy(&cond));
#endif
}
@@ -159,14 +150,12 @@ namespace boost
#ifdef BOOST_PTHREAD_HAS_TIMEDLOCK
void lock()
{
int const res=pthread_mutex_lock(&m);
BOOST_ASSERT(!res);
BOOST_VERIFY(!pthread_mutex_lock(&m));
}
void unlock()
{
int const res=pthread_mutex_unlock(&m);
BOOST_ASSERT(!res);
BOOST_VERIFY(!pthread_mutex_unlock(&m));
}
bool try_lock()
@@ -186,7 +175,7 @@ namespace boost
void lock()
{
boost::pthread::pthread_mutex_scoped_lock const local_lock(&m);
if(is_locked && owner==pthread_self())
if(is_locked && pthread_equal(owner,pthread_self()))
{
++count;
return;
@@ -194,8 +183,7 @@ namespace boost
while(is_locked)
{
int const cond_res=pthread_cond_wait(&cond,&m);
BOOST_ASSERT(!cond_res);
BOOST_VERIFY(!pthread_cond_wait(&cond,&m));
}
is_locked=true;
++count;
@@ -209,14 +197,13 @@ namespace boost
{
is_locked=false;
}
int const res=pthread_cond_signal(&cond);
BOOST_ASSERT(!res);
BOOST_VERIFY(!pthread_cond_signal(&cond));
}
bool try_lock()
{
boost::pthread::pthread_mutex_scoped_lock const local_lock(&m);
if(is_locked && owner!=pthread_self())
if(is_locked && !pthread_equal(owner,pthread_self()))
{
return false;
}
@@ -230,7 +217,7 @@ namespace boost
{
struct timespec const timeout=detail::get_timespec(abs_time);
boost::pthread::pthread_mutex_scoped_lock const local_lock(&m);
if(is_locked && owner==pthread_self())
if(is_locked && pthread_equal(owner,pthread_self()))
{
++count;
return true;

View File

@@ -10,6 +10,7 @@
#include <boost/assert.hpp>
#include <boost/static_assert.hpp>
#include <boost/thread/mutex.hpp>
#include <boost/thread/thread.hpp>
#include <boost/thread/condition_variable.hpp>
namespace boost

View File

@@ -33,7 +33,7 @@ namespace boost
namespace this_thread
{
detail::thread_id get_id();
BOOST_THREAD_DECL detail::thread_id get_id();
}
namespace detail
@@ -208,22 +208,22 @@ namespace boost
~restore_interruption();
};
inline thread::id get_id()
BOOST_THREAD_DECL inline thread::id get_id()
{
return thread::id(pthread_self());
}
void BOOST_THREAD_DECL interruption_point();
bool BOOST_THREAD_DECL interruption_enabled();
bool BOOST_THREAD_DECL interruption_requested();
BOOST_THREAD_DECL void interruption_point();
BOOST_THREAD_DECL bool interruption_enabled();
BOOST_THREAD_DECL bool interruption_requested();
inline void yield()
BOOST_THREAD_DECL inline void yield()
{
thread::yield();
}
template<typename TimeDuration>
inline void sleep(TimeDuration const& rel_time)
BOOST_THREAD_DECL inline void sleep(TimeDuration const& rel_time)
{
thread::sleep(get_system_time()+rel_time);
}
@@ -254,13 +254,13 @@ namespace boost
}
};
void add_thread_exit_function(thread_exit_function_base*);
BOOST_THREAD_DECL void add_thread_exit_function(thread_exit_function_base*);
}
namespace this_thread
{
template<typename F>
void at_thread_exit(F f)
inline void at_thread_exit(F f)
{
detail::thread_exit_function_base* const thread_exit_func=new detail::thread_exit_function<F>(f);
detail::add_thread_exit_function(thread_exit_func);

View File

@@ -1,5 +1,10 @@
#ifndef BOOST_THREAD_PTHREAD_TIMESPEC_HPP
#define BOOST_THREAD_PTHREAD_TIMESPEC_HPP
// (C) Copyright 2007 Anthony Williams
//
// 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)
#include <boost/thread/thread_time.hpp>
#include <boost/date_time/posix_time/conversion.hpp>

View File

@@ -1,5 +1,11 @@
#ifndef BOOST_THREAD_TIME_HPP
#define BOOST_THREAD_TIME_HPP
// (C) Copyright 2007 Anthony Williams
//
// 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)
#include <boost/date_time/microsec_time_clock.hpp>
#include <boost/date_time/posix_time/posix_time_types.hpp>

View File

@@ -59,8 +59,7 @@ namespace boost
void lock()
{
bool const success=timed_lock(::boost::detail::get_system_time_sentinel());
BOOST_ASSERT(success);
BOOST_VERIFY(timed_lock(::boost::detail::get_system_time_sentinel()));
}
bool timed_lock(::boost::system_time const& wait_until)
{

View File

@@ -79,8 +79,7 @@ namespace boost
{
if(entry.semaphore)
{
unsigned long const close_result=detail::win32::CloseHandle(entry.semaphore);
BOOST_ASSERT(close_result);
BOOST_VERIFY(detail::win32::CloseHandle(entry.semaphore));
entry.semaphore=0;
}
entry.notified=false;

View File

@@ -40,13 +40,11 @@ namespace boost
explicit win32_mutex_scoped_lock(void* mutex_handle_):
mutex_handle(mutex_handle_)
{
unsigned long const res=win32::WaitForSingleObject(mutex_handle,win32::infinite);
BOOST_ASSERT(!res);
BOOST_VERIFY(!win32::WaitForSingleObject(mutex_handle,win32::infinite));
}
~win32_mutex_scoped_lock()
{
bool const success=win32::ReleaseMutex(mutex_handle)!=0;
BOOST_ASSERT(success);
BOOST_VERIFY(win32::ReleaseMutex(mutex_handle)!=0);
}
};

View File

@@ -57,14 +57,12 @@ namespace boost
{
if(old_state.exclusive_waiting)
{
bool const success=detail::win32::ReleaseSemaphore(exclusive_sem,1,NULL)!=0;
BOOST_ASSERT(success);
BOOST_VERIFY(detail::win32::ReleaseSemaphore(exclusive_sem,1,NULL)!=0);
}
if(old_state.shared_waiting || old_state.exclusive_waiting)
{
bool const success=detail::win32::ReleaseSemaphore(unlock_sem,old_state.shared_waiting + (old_state.exclusive_waiting?1:0),NULL)!=0;
BOOST_ASSERT(success);
BOOST_VERIFY(detail::win32::ReleaseSemaphore(unlock_sem,old_state.shared_waiting + (old_state.exclusive_waiting?1:0),NULL)!=0);
}
}
@@ -112,8 +110,7 @@ namespace boost
void lock_shared()
{
bool const success=timed_lock_shared(::boost::detail::get_system_time_sentinel());
BOOST_ASSERT(success);
BOOST_VERIFY(timed_lock_shared(::boost::detail::get_system_time_sentinel()));
}
bool timed_lock_shared(boost::system_time const& wait_until)
@@ -218,8 +215,7 @@ namespace boost
{
if(old_state.upgrade)
{
bool const success=detail::win32::ReleaseSemaphore(upgrade_sem,1,NULL)!=0;
BOOST_ASSERT(success);
BOOST_VERIFY(detail::win32::ReleaseSemaphore(upgrade_sem,1,NULL)!=0);
}
else
{
@@ -235,8 +231,7 @@ namespace boost
void lock()
{
bool const success=timed_lock(::boost::detail::get_system_time_sentinel());
BOOST_ASSERT(success);
BOOST_VERIFY(timed_lock(::boost::detail::get_system_time_sentinel()));
}
bool timed_lock(boost::system_time const& wait_until)
@@ -364,8 +359,7 @@ namespace boost
return;
}
unsigned long const res=detail::win32::WaitForSingleObject(unlock_sem,detail::win32::infinite);
BOOST_ASSERT(res==0);
BOOST_VERIFY(!detail::win32::WaitForSingleObject(unlock_sem,detail::win32::infinite));
}
}
@@ -421,8 +415,7 @@ namespace boost
{
if(!last_reader)
{
unsigned long const res=detail::win32::WaitForSingleObject(upgrade_sem,detail::win32::infinite);
BOOST_ASSERT(res==0);
BOOST_VERIFY(!detail::win32::WaitForSingleObject(upgrade_sem,detail::win32::infinite));
}
break;
}

View File

@@ -204,8 +204,7 @@ namespace boost
inline void release_semaphore(handle semaphore,long count)
{
bool const success=ReleaseSemaphore(semaphore,count,0)!=0;
BOOST_ASSERT(success);
BOOST_VERIFY(ReleaseSemaphore(semaphore,count,0)!=0);
}
class handle_manager
@@ -219,8 +218,7 @@ namespace boost
{
if(handle_to_manage && handle_to_manage!=invalid_handle_value)
{
unsigned long const result=CloseHandle(handle_to_manage);
BOOST_ASSERT(result);
BOOST_VERIFY(CloseHandle(handle_to_manage));
}
}

View File

@@ -55,8 +55,7 @@ namespace boost
void create_current_thread_tls_key()
{
int const res=pthread_key_create(&current_thread_tls_key,NULL);
BOOST_ASSERT(!res);
BOOST_VERIFY(!pthread_key_create(&current_thread_tls_key,NULL));
}
}
@@ -69,8 +68,7 @@ namespace boost
void set_current_thread_data(detail::thread_data_base* new_data)
{
boost::call_once(current_thread_tls_init_flag,create_current_thread_tls_key);
int const res=pthread_setspecific(current_thread_tls_key,new_data);
BOOST_ASSERT(!res);
BOOST_VERIFY(!pthread_setspecific(current_thread_tls_key,new_data));
}
}
@@ -172,8 +170,7 @@ namespace boost
if(do_join)
{
void* result=0;
int const res=pthread_join(local_thread_info->thread_handle,&result);
BOOST_ASSERT(!res);
BOOST_VERIFY(!pthread_join(local_thread_info->thread_handle,&result));
lock_guard<mutex> lock(local_thread_info->data_mutex);
local_thread_info->joined=true;
local_thread_info->done_condition.notify_all();
@@ -220,8 +217,7 @@ namespace boost
if(do_join)
{
void* result=0;
int const res=pthread_join(local_thread_info->thread_handle,&result);
BOOST_ASSERT(!res);
BOOST_VERIFY(!pthread_join(local_thread_info->thread_handle,&result));
lock_guard<mutex> lock(local_thread_info->data_mutex);
local_thread_info->joined=true;
local_thread_info->done_condition.notify_all();
@@ -255,8 +251,7 @@ namespace boost
lock_guard<mutex> lock(local_thread_info->data_mutex);
if(!local_thread_info->join_started)
{
int const res=pthread_detach(local_thread_info->thread_handle);
BOOST_ASSERT(!res);
BOOST_VERIFY(!pthread_detach(local_thread_info->thread_handle));
local_thread_info->join_started=true;
local_thread_info->joined=true;
}
@@ -281,9 +276,7 @@ namespace boost
# if defined(BOOST_HAS_PTHREAD_DELAY_NP)
timespec ts;
to_timespec_duration(xt, ts);
int res = 0;
res = pthread_delay_np(&ts);
BOOST_ASSERT(res == 0);
BOOST_VERIFY(!pthread_delay_np(&ts));
# elif defined(BOOST_HAS_NANOSLEEP)
timespec ts;
to_timespec_duration(xt, ts);
@@ -308,13 +301,9 @@ namespace boost
void thread::yield()
{
# if defined(BOOST_HAS_SCHED_YIELD)
int res = 0;
res = sched_yield();
BOOST_ASSERT(res == 0);
BOOST_VERIFY(!sched_yield());
# elif defined(BOOST_HAS_PTHREAD_YIELD)
int res = 0;
res = pthread_yield();
BOOST_ASSERT(res == 0);
BOOST_VERIFY(!pthread_yield());
# else
xtime xt;
xtime_get(&xt, TIME_UTC);
@@ -349,8 +338,7 @@ namespace boost
local_thread_info->interrupt_requested=true;
if(local_thread_info->current_cond)
{
int const res=pthread_cond_broadcast(local_thread_info->current_cond);
BOOST_ASSERT(!res);
BOOST_VERIFY(!pthread_cond_broadcast(local_thread_info->current_cond));
}
}
}

View File

@@ -17,11 +17,6 @@
#include <stdexcept>
#include <cassert>
#if defined(BOOST_HAS_WINTHREADS)
# include <windows.h>
# include <boost/thread/detail/tss_hooks.hpp>
#endif
namespace {
typedef std::vector<void*> tss_slots;

View File

@@ -58,8 +58,7 @@ namespace boost
void set_current_thread_data(detail::thread_data_base* new_data)
{
boost::call_once(current_thread_tls_init_flag,create_current_thread_tls_key);
BOOL const res=TlsSetValue(current_thread_tls_key,new_data);
BOOST_ASSERT(res);
BOOST_VERIFY(TlsSetValue(current_thread_tls_key,new_data));
}
#endif

View File

@@ -30,7 +30,7 @@
class CScopedCSLock
{
public:
CScopedCSLock(LPCRITICAL_SECTION cs) : cs(cs), lk(true) {
CScopedCSLock(LPCRITICAL_SECTION cs) : lk(true), cs(cs) {
::EnterCriticalSection(cs);
}
~CScopedCSLock() {

View File

@@ -6,6 +6,7 @@
#include <boost/test/unit_test.hpp>
#include <boost/thread/thread.hpp>
#include <boost/thread/mutex.hpp>
#include <boost/thread/condition_variable.hpp>
#include <boost/thread/shared_mutex.hpp>
#include <boost/thread/xtime.hpp>
#include "util.inl"
@@ -29,16 +30,19 @@ namespace
unsigned& simultaneous_running_count;
unsigned& max_simultaneous_running;
boost::mutex& unblocked_count_mutex;
boost::condition_variable& unblocked_condition;
boost::mutex& finish_mutex;
public:
locking_thread(boost::shared_mutex& rw_mutex_,
unsigned& unblocked_count_,
boost::mutex& unblocked_count_mutex_,
boost::condition_variable& unblocked_condition_,
boost::mutex& finish_mutex_,
unsigned& simultaneous_running_count_,
unsigned& max_simultaneous_running_):
rw_mutex(rw_mutex_),
unblocked_count(unblocked_count_),
unblocked_condition(unblocked_condition_),
simultaneous_running_count(simultaneous_running_count_),
max_simultaneous_running(max_simultaneous_running_),
unblocked_count_mutex(unblocked_count_mutex_),
@@ -54,6 +58,7 @@ namespace
{
boost::mutex::scoped_lock ublock(unblocked_count_mutex);
++unblocked_count;
unblocked_condition.notify_one();
++simultaneous_running_count;
if(simultaneous_running_count>max_simultaneous_running)
{
@@ -84,15 +89,23 @@ void test_multiple_readers()
unsigned simultaneous_running_count=0;
unsigned max_simultaneous_running=0;
boost::mutex unblocked_count_mutex;
boost::condition_variable unblocked_condition;
boost::mutex finish_mutex;
boost::mutex::scoped_lock finish_lock(finish_mutex);
for(unsigned i=0;i<number_of_threads;++i)
{
pool.create_thread(locking_thread<boost::shared_lock<boost::shared_mutex> >(rw_mutex,unblocked_count,unblocked_count_mutex,finish_mutex,simultaneous_running_count,max_simultaneous_running));
pool.create_thread(locking_thread<boost::shared_lock<boost::shared_mutex> >(rw_mutex,unblocked_count,unblocked_count_mutex,unblocked_condition,
finish_mutex,simultaneous_running_count,max_simultaneous_running));
}
boost::thread::sleep(delay(1));
{
boost::mutex::scoped_lock lk(unblocked_count_mutex);
while(unblocked_count<number_of_threads)
{
unblocked_condition.wait(lk);
}
}
CHECK_LOCKED_VALUE_EQUAL(unblocked_count_mutex,unblocked_count,number_of_threads);
@@ -114,15 +127,17 @@ void test_only_one_writer_permitted()
unsigned simultaneous_running_count=0;
unsigned max_simultaneous_running=0;
boost::mutex unblocked_count_mutex;
boost::condition_variable unblocked_condition;
boost::mutex finish_mutex;
boost::mutex::scoped_lock finish_lock(finish_mutex);
for(unsigned i=0;i<number_of_threads;++i)
{
pool.create_thread(locking_thread<boost::unique_lock<boost::shared_mutex> >(rw_mutex,unblocked_count,unblocked_count_mutex,finish_mutex,simultaneous_running_count,max_simultaneous_running));
pool.create_thread(locking_thread<boost::unique_lock<boost::shared_mutex> >(rw_mutex,unblocked_count,unblocked_count_mutex,unblocked_condition,
finish_mutex,simultaneous_running_count,max_simultaneous_running));
}
boost::thread::sleep(delay(1));
boost::thread::sleep(delay(2));
CHECK_LOCKED_VALUE_EQUAL(unblocked_count_mutex,unblocked_count,1U);
@@ -143,13 +158,22 @@ void test_reader_blocks_writer()
unsigned simultaneous_running_count=0;
unsigned max_simultaneous_running=0;
boost::mutex unblocked_count_mutex;
boost::condition_variable unblocked_condition;
boost::mutex finish_mutex;
boost::mutex::scoped_lock finish_lock(finish_mutex);
pool.create_thread(locking_thread<boost::shared_lock<boost::shared_mutex> >(rw_mutex,unblocked_count,unblocked_count_mutex,finish_mutex,simultaneous_running_count,max_simultaneous_running));
boost::thread::sleep(delay(1));
pool.create_thread(locking_thread<boost::shared_lock<boost::shared_mutex> >(rw_mutex,unblocked_count,unblocked_count_mutex,unblocked_condition,
finish_mutex,simultaneous_running_count,max_simultaneous_running));
{
boost::mutex::scoped_lock lk(unblocked_count_mutex);
while(unblocked_count<1)
{
unblocked_condition.wait(lk);
}
}
CHECK_LOCKED_VALUE_EQUAL(unblocked_count_mutex,unblocked_count,1U);
pool.create_thread(locking_thread<boost::unique_lock<boost::shared_mutex> >(rw_mutex,unblocked_count,unblocked_count_mutex,finish_mutex,simultaneous_running_count,max_simultaneous_running));
pool.create_thread(locking_thread<boost::unique_lock<boost::shared_mutex> >(rw_mutex,unblocked_count,unblocked_count_mutex,unblocked_condition,
finish_mutex,simultaneous_running_count,max_simultaneous_running));
boost::thread::sleep(delay(1));
CHECK_LOCKED_VALUE_EQUAL(unblocked_count_mutex,unblocked_count,1U);
@@ -171,6 +195,7 @@ void test_unlocking_writer_unblocks_all_readers()
unsigned simultaneous_running_count=0;
unsigned max_simultaneous_running=0;
boost::mutex unblocked_count_mutex;
boost::condition_variable unblocked_condition;
boost::mutex finish_mutex;
boost::mutex::scoped_lock finish_lock(finish_mutex);
@@ -178,14 +203,22 @@ void test_unlocking_writer_unblocks_all_readers()
for(unsigned i=0;i<reader_count;++i)
{
pool.create_thread(locking_thread<boost::shared_lock<boost::shared_mutex> >(rw_mutex,unblocked_count,unblocked_count_mutex,finish_mutex,simultaneous_running_count,max_simultaneous_running));
pool.create_thread(locking_thread<boost::shared_lock<boost::shared_mutex> >(rw_mutex,unblocked_count,unblocked_count_mutex,unblocked_condition,
finish_mutex,simultaneous_running_count,max_simultaneous_running));
}
boost::thread::sleep(delay(1));
CHECK_LOCKED_VALUE_EQUAL(unblocked_count_mutex,unblocked_count,0U);
write_lock.unlock();
boost::thread::sleep(delay(1));
{
boost::mutex::scoped_lock lk(unblocked_count_mutex);
while(unblocked_count<reader_count)
{
unblocked_condition.wait(lk);
}
}
CHECK_LOCKED_VALUE_EQUAL(unblocked_count_mutex,unblocked_count,reader_count);
finish_lock.unlock();
@@ -204,6 +237,7 @@ void test_unlocking_last_reader_only_unblocks_one_writer()
unsigned simultaneous_running_writers=0;
unsigned max_simultaneous_writers=0;
boost::mutex unblocked_count_mutex;
boost::condition_variable unblocked_condition;
boost::mutex finish_reading_mutex;
boost::mutex::scoped_lock finish_reading_lock(finish_reading_mutex);
boost::mutex finish_writing_mutex;
@@ -214,18 +248,34 @@ void test_unlocking_last_reader_only_unblocks_one_writer()
for(unsigned i=0;i<reader_count;++i)
{
pool.create_thread(locking_thread<boost::shared_lock<boost::shared_mutex> >(rw_mutex,unblocked_count,unblocked_count_mutex,finish_reading_mutex,simultaneous_running_readers,max_simultaneous_readers));
pool.create_thread(locking_thread<boost::shared_lock<boost::shared_mutex> >(rw_mutex,unblocked_count,unblocked_count_mutex,unblocked_condition,
finish_reading_mutex,simultaneous_running_readers,max_simultaneous_readers));
}
boost::thread::sleep(delay(1));
for(unsigned i=0;i<writer_count;++i)
{
pool.create_thread(locking_thread<boost::unique_lock<boost::shared_mutex> >(rw_mutex,unblocked_count,unblocked_count_mutex,finish_writing_mutex,simultaneous_running_writers,max_simultaneous_writers));
pool.create_thread(locking_thread<boost::unique_lock<boost::shared_mutex> >(rw_mutex,unblocked_count,unblocked_count_mutex,unblocked_condition,
finish_writing_mutex,simultaneous_running_writers,max_simultaneous_writers));
}
boost::thread::sleep(delay(2));
{
boost::mutex::scoped_lock lk(unblocked_count_mutex);
while(unblocked_count<reader_count)
{
unblocked_condition.wait(lk);
}
}
boost::thread::sleep(delay(1));
CHECK_LOCKED_VALUE_EQUAL(unblocked_count_mutex,unblocked_count,reader_count);
finish_reading_lock.unlock();
boost::thread::sleep(delay(2));
{
boost::mutex::scoped_lock lk(unblocked_count_mutex);
while(unblocked_count<(reader_count+1))
{
unblocked_condition.wait(lk);
}
}
CHECK_LOCKED_VALUE_EQUAL(unblocked_count_mutex,unblocked_count,reader_count+1);
finish_writing_lock.unlock();
@@ -246,12 +296,14 @@ void test_only_one_upgrade_lock_permitted()
unsigned simultaneous_running_count=0;
unsigned max_simultaneous_running=0;
boost::mutex unblocked_count_mutex;
boost::condition_variable unblocked_condition;
boost::mutex finish_mutex;
boost::mutex::scoped_lock finish_lock(finish_mutex);
for(unsigned i=0;i<number_of_threads;++i)
{
pool.create_thread(locking_thread<boost::upgrade_lock<boost::shared_mutex> >(rw_mutex,unblocked_count,unblocked_count_mutex,finish_mutex,simultaneous_running_count,max_simultaneous_running));
pool.create_thread(locking_thread<boost::upgrade_lock<boost::shared_mutex> >(rw_mutex,unblocked_count,unblocked_count_mutex,unblocked_condition,
finish_mutex,simultaneous_running_count,max_simultaneous_running));
}
boost::thread::sleep(delay(1));
@@ -275,6 +327,7 @@ void test_can_lock_upgrade_if_currently_locked_shared()
unsigned simultaneous_running_count=0;
unsigned max_simultaneous_running=0;
boost::mutex unblocked_count_mutex;
boost::condition_variable unblocked_condition;
boost::mutex finish_mutex;
boost::mutex::scoped_lock finish_lock(finish_mutex);
@@ -282,10 +335,19 @@ void test_can_lock_upgrade_if_currently_locked_shared()
for(unsigned i=0;i<reader_count;++i)
{
pool.create_thread(locking_thread<boost::shared_lock<boost::shared_mutex> >(rw_mutex,unblocked_count,unblocked_count_mutex,finish_mutex,simultaneous_running_count,max_simultaneous_running));
pool.create_thread(locking_thread<boost::shared_lock<boost::shared_mutex> >(rw_mutex,unblocked_count,unblocked_count_mutex,unblocked_condition,
finish_mutex,simultaneous_running_count,max_simultaneous_running));
}
pool.create_thread(locking_thread<boost::upgrade_lock<boost::shared_mutex> >(rw_mutex,unblocked_count,unblocked_count_mutex,finish_mutex,simultaneous_running_count,max_simultaneous_running));
boost::thread::sleep(delay(1));
pool.create_thread(locking_thread<boost::upgrade_lock<boost::shared_mutex> >(rw_mutex,unblocked_count,unblocked_count_mutex,unblocked_condition,
finish_mutex,simultaneous_running_count,max_simultaneous_running));
{
boost::mutex::scoped_lock lk(unblocked_count_mutex);
while(unblocked_count<(reader_count+1))
{
unblocked_condition.wait(lk);
}
}
CHECK_LOCKED_VALUE_EQUAL(unblocked_count_mutex,unblocked_count,reader_count+1);
finish_lock.unlock();