Stxxl  1.3.2
request_queue_impl_worker.h
1 /***************************************************************************
2  * include/stxxl/bits/io/request_queue_impl_worker.h
3  *
4  * Part of the STXXL. See http://stxxl.sourceforge.net
5  *
6  * Copyright (C) 2002 Roman Dementiev <[email protected]>
7  * Copyright (C) 2008, 2009 Andreas Beckmann <[email protected]>
8  * Copyright (C) 2009 Johannes Singler <[email protected]>
9  *
10  * Distributed under the Boost Software License, Version 1.0.
11  * (See accompanying file LICENSE_1_0.txt or copy at
12  * http://www.boost.org/LICENSE_1_0.txt)
13  **************************************************************************/
14 
15 #ifndef STXXL_IO_REQUEST_QUEUE_IMPL_WORKER_HEADER
16 #define STXXL_IO_REQUEST_QUEUE_IMPL_WORKER_HEADER
17 
18 #ifdef STXXL_BOOST_CONFIG
19  #include <boost/config.hpp>
20 #endif
21 
22 #ifdef STXXL_BOOST_THREADS // Use Portable Boost threads
23  #include <boost/thread/thread.hpp>
24 #else
25  #include <pthread.h>
26 #endif
27 
28 #include <stxxl/bits/io/request_queue.h>
29 #include <stxxl/bits/common/semaphore.h>
30 #include <stxxl/bits/common/state.h>
31 
32 
33 __STXXL_BEGIN_NAMESPACE
34 
37 
38 class request_queue_impl_worker : public request_queue
39 {
40 protected:
41  enum thread_state { NOT_RUNNING, RUNNING, TERMINATING, TERMINATE = TERMINATING };
42 
43 #ifdef STXXL_BOOST_THREADS
44  typedef boost::thread * thread_type;
45 #else
46  typedef pthread_t thread_type;
47 #endif
48 
49 protected:
50  void start_thread(void * (*worker)(void *), void * arg, thread_type & t, state<thread_state> & s);
51  void stop_thread(thread_type & t, state<thread_state> & s, semaphore & sem);
52 };
53 
55 
56 __STXXL_END_NAMESPACE
57 
58 #endif // !STXXL_IO_REQUEST_QUEUE_IMPL_WORKER_HEADER
59 // vim: et:ts=4:sw=4