http://stxxl.sourceforge.net
<dementiev@mpi-sb.mpg.de>
<beckmann@cs.uni-frankfurt.de>
<singler@ira.uka.de>
<tb@panthema.net>
http://www.boost.org/LICENSE_1_0.txt
#include <stxxl/bits/common/error_handling.h>
#include <stxxl/bits/common/semaphore.h>
#include <stxxl/bits/common/state.h>
#include <stxxl/bits/config.h>
#include <stxxl/bits/io/request_queue_impl_worker.h>
#include <stxxl/bits/namespace.h>
#include <cassert>
#include <cstddef>
#if STXXL_BOOST_THREADS
#include <boost/bind.hpp>
#endif
#if STXXL_STD_THREADS && STXXL_MSVC >= 1700
#include <windows.h>
#endif
STXXL_BEGIN_NAMESPACE
void request_queue_impl_worker::start_thread(void* (* worker)(void*), void* arg, thread_type& t, state<thread_state>& s)
{
assert(s() == NOT_RUNNING);
#if STXXL_STD_THREADS
t = new std::thread(worker, arg);
#elif STXXL_BOOST_THREADS
t = new boost::thread(boost::bind(worker, arg));
#else
STXXL_CHECK_PTHREAD_CALL(pthread_create(&t, NULL, worker, arg));
#endif
s.set_to(RUNNING);
}
void request_queue_impl_worker::stop_thread(thread_type& t, state<thread_state>& s, semaphore& sem)
{
assert(s() == RUNNING);
s.set_to(TERMINATING);
sem++;
#if STXXL_STD_THREADS
#if STXXL_MSVC >= 1700
WaitForSingleObject(t->native_handle(), INFINITE);
CloseHandle(t->native_handle());
#else
t->join();
delete t;
#endif
t = NULL;
#elif STXXL_BOOST_THREADS
t->join();
delete t;
t = NULL;
#else
STXXL_CHECK_PTHREAD_CALL(pthread_join(t, NULL));
#endif
assert(s() == TERMINATED);
s.set_to(NOT_RUNNING);
}
STXXL_END_NAMESPACE