Thrill  0.1
request_queue_impl_qwqr.hpp
Go to the documentation of this file.
1 /***************************************************************************
2  * foxxll/io/request_queue_impl_qwqr.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  * 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 FOXXLL_IO_REQUEST_QUEUE_IMPL_QWQR_HEADER
17 #define FOXXLL_IO_REQUEST_QUEUE_IMPL_QWQR_HEADER
18 
19 #include <list>
20 #include <mutex>
21 
22 #include <tlx/unused.hpp>
23 
25 
26 namespace foxxll {
27 
28 //! \addtogroup foxxll_reqlayer
29 //! \{
30 
31 //! Implementation of a local request queue having two queues, one for read and
32 //! one for write requests, thus having two threads. This is the default
33 //! implementation.
35 {
36  constexpr static bool debug = false;
37 
38 private:
40  using queue_type = std::list<request_ptr>;
41 
42  std::mutex write_mutex_;
43  std::mutex read_mutex_;
46 
48  std::thread thread_;
50 
51  static const priority_op priority_op_ = WRITE;
52 
53  static void * worker(void* arg);
54 
55 public:
56  // \param n max number of requests simultaneously submitted to disk
57  explicit request_queue_impl_qwqr(int n = 1);
58 
59  // in a multi-threaded setup this does not work as intended
60  // also there were race conditions possible
61  // and actually an old value was never restored once a new one was set ...
62  // so just disable it and all it's nice implications
63  void set_priority_op(const priority_op& op) final;
64  void add_request(request_ptr& req) final;
65  bool cancel_request(request_ptr& req) final;
67 };
68 
69 //! \}
70 
71 } // namespace foxxll
72 
73 #endif // !FOXXLL_IO_REQUEST_QUEUE_IMPL_QWQR_HEADER
74 
75 /**************************************************************************/
A simple semaphore implementation using C++11 synchronization methods.
Definition: semaphore.hpp:26
void add_request(request_ptr &req) final
void set_priority_op(const priority_op &op) final
FOXXLL library namespace
High-performance smart pointer used as a wrapping reference counting pointer.
bool cancel_request(request_ptr &req) final
shared_state< thread_state > thread_state_