Thrill  0.1
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups Pages
request_queue_impl_1q.hpp
Go to the documentation of this file.
1 /***************************************************************************
2  * foxxll/io/request_queue_impl_1q.hpp
3  *
4  * Part of FOXXLL. See http://foxxll.org
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 FOXXLL_IO_REQUEST_QUEUE_IMPL_1Q_HEADER
16 #define FOXXLL_IO_REQUEST_QUEUE_IMPL_1Q_HEADER
17 
18 #include <list>
19 #include <mutex>
20 
21 #include <tlx/unused.hpp>
22 
24 
25 namespace foxxll {
26 
27 //! \addtogroup foxxll_reqlayer
28 //! \{
29 
30 //! Implementation of a local request queue having only one queue for both read
31 //! and write requests, thus having only one thread.
33 {
34 private:
35  using self = request_queue_impl_1q;
36  using queue_type = std::list<request_ptr>;
37 
38  std::mutex queue_mutex_;
40 
42  std::thread thread_;
44 
45  static const priority_op priority_op_ = WRITE;
46 
47  static void * worker(void* arg);
48 
49 public:
50  // \param n max number of requests simultaneously submitted to disk
51  explicit request_queue_impl_1q(int n = 1);
52 
53  // in a multi-threaded setup this does not work as intended
54  // also there were race conditions possible
55  // and actually an old value was never restored once a new one was set ...
56  // so just disable it and all it's nice implications
57  void set_priority_op(const priority_op& op) final;
58 
59  void add_request(request_ptr& req) final;
60  bool cancel_request(request_ptr& req) final;
62 };
63 
64 //! \}
65 
66 } // namespace foxxll
67 
68 #endif // !FOXXLL_IO_REQUEST_QUEUE_IMPL_1Q_HEADER
69 
70 /**************************************************************************/
A simple semaphore implementation using C++11 synchronization methods.
Definition: semaphore.hpp:26
shared_state< thread_state > thread_state_
void add_request(request_ptr &req) final
static const priority_op priority_op_
void set_priority_op(const priority_op &op) final
bool cancel_request(request_ptr &req) final
High-performance smart pointer used as a wrapping reference counting pointer.
std::list< request_ptr > queue_type