// William E. Kempf
// Copyright (C) 2007-8 Anthony Williams
//
-// Distributed under the Boost Software License, Version 1.0. (See accompanying
+// 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/detail/config.hpp>
}
}
}
-
+
void create_current_thread_tls_key()
{
BOOST_VERIFY(!pthread_key_create(¤t_thread_tls_key,&tls_destructor));
}
}
-
+
boost::detail::thread_data_base* get_current_thread_data()
{
boost::call_once(current_thread_tls_init_flag,create_current_thread_tls_key);
BOOST_VERIFY(!pthread_setspecific(current_thread_tls_key,new_data));
}
}
-
+
namespace
{
extern "C"
{
interrupt_enabled=false;
}
-
+
void run()
{}
if(local_thread_info)
{
bool do_join=false;
-
+
{
unique_lock<mutex> lock(local_thread_info->data_mutex);
while(!local_thread_info->done)
local_thread_info->done_condition.wait(lock);
}
do_join=!local_thread_info->join_started;
-
+
if(do_join)
{
local_thread_info->join_started=true;
local_thread_info->joined=true;
local_thread_info->done_condition.notify_all();
}
-
+
lock_guard<mutex> l1(thread_info_mutex);
if(thread_info==local_thread_info)
{
if(local_thread_info)
{
bool do_join=false;
-
+
{
unique_lock<mutex> lock(local_thread_info->data_mutex);
while(!local_thread_info->done)
}
}
do_join=!local_thread_info->join_started;
-
+
if(do_join)
{
local_thread_info->join_started=true;
local_thread_info->joined=true;
local_thread_info->done_condition.notify_all();
}
-
+
lock_guard<mutex> l1(thread_info_mutex);
if(thread_info==local_thread_info)
{
lock_guard<mutex> l1(thread_info_mutex);
thread_info.swap(local_thread_info);
}
-
+
if(local_thread_info)
{
lock_guard<mutex> lock(local_thread_info->data_mutex);
namespace this_thread
{
-
+
void sleep(const system_time& st)
{
detail::thread_data_base* const thread_info=detail::get_current_thread_data();
-
+
if(thread_info)
{
unique_lock<mutex> lk(thread_info->sleep_mutex);
- while(thread_info->sleep_condition.timed_wait(lk,st));
+ while(thread_info->sleep_condition.timed_wait(lk,st)) {}
}
else
{
xtime const xt=get_xtime(st);
-
+
for (int foo=0; foo < 5; ++foo)
{
# if defined(BOOST_HAS_PTHREAD_DELAY_NP)
# elif defined(BOOST_HAS_NANOSLEEP)
timespec ts;
to_timespec_duration(xt, ts);
-
+
// nanosleep takes a timespec that is an offset, not
// an absolute time.
nanosleep(&ts, 0);
return pthread_t();
}
}
-
-
+
+
namespace this_thread
{
}
}
}
-
+
bool interruption_enabled()
{
boost::detail::thread_data_base* const thread_info=detail::get_current_thread_data();
return thread_info && thread_info->interrupt_enabled;
}
-
+
bool interruption_requested()
{
boost::detail::thread_data_base* const thread_info=detail::get_current_thread_data();
detail::get_current_thread_data()->interrupt_enabled=false;
}
}
-
+
disable_interruption::~disable_interruption()
{
if(detail::get_current_thread_data())
detail::get_current_thread_data()->interrupt_enabled=true;
}
}
-
+
restore_interruption::~restore_interruption()
{
if(detail::get_current_thread_data())
detail::thread_data_base* const current_thread_data(get_or_make_current_thread_data());
current_thread_data->tss_data.erase(key);
}
-
+
void set_tss_data(void const* key,
boost::shared_ptr<tss_cleanup_function> func,
void* tss_data,bool cleanup_existing)