STXXL  1.4-dev
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups Pages
request_queue_impl_worker.h
Go to the documentation of this file.
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  * Copyright (C) 2013 Timo Bingmann <[email protected]>
10  *
11  * Distributed under the Boost Software License, Version 1.0.
12  * (See accompanying file LICENSE_1_0.txt or copy at
13  * http://www.boost.org/LICENSE_1_0.txt)
14  **************************************************************************/
15 
16 #ifndef STXXL_IO_REQUEST_QUEUE_IMPL_WORKER_HEADER
17 #define STXXL_IO_REQUEST_QUEUE_IMPL_WORKER_HEADER
18 
19 #include <stxxl/bits/config.h>
20 
21 #if STXXL_STD_THREADS
22  #include <thread>
23 #elif STXXL_BOOST_THREADS
24  #include <boost/thread/thread.hpp>
25 #elif STXXL_POSIX_THREADS
26  #include <pthread.h>
27 #else
28  #error "Thread implementation not detected."
29 #endif
30 
34 
36 
37 //! \addtogroup reqlayer
38 //! \{
39 
40 //! Implementation of request queue worker threads. Worker threads can be
41 //! started by start_thread and stopped with stop_thread. The queue state is
42 //! checked before termination and updated afterwards.
44 {
45 protected:
46  enum thread_state { NOT_RUNNING, RUNNING, TERMINATING, TERMINATED };
47 
48 #if STXXL_STD_THREADS
49  typedef std::thread* thread_type;
50 #elif STXXL_BOOST_THREADS
51  typedef boost::thread* thread_type;
52 #else
53  typedef pthread_t thread_type;
54 #endif
55 
56 protected:
57  void start_thread(void* (*worker)(void*), void* arg, thread_type& t, state<thread_state>& s);
58  void stop_thread(thread_type& t, state<thread_state>& s, semaphore& sem);
59 };
60 
61 //! \}
62 
64 
65 #endif // !STXXL_IO_REQUEST_QUEUE_IMPL_WORKER_HEADER
66 // vim: et:ts=4:sw=4
Interface of a request_queue to which requests can be added and canceled.
Definition: request_queue.h:26
Implementation of request queue worker threads. Worker threads can be started by start_thread and sto...
#define STXXL_BEGIN_NAMESPACE
Definition: namespace.h:16
#define STXXL_END_NAMESPACE
Definition: namespace.h:17