Thrill  0.1
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups Pages
disk_queues.hpp
Go to the documentation of this file.
1 /***************************************************************************
2  * foxxll/io/disk_queues.hpp
3  *
4  * Part of FOXXLL. See http://foxxll.org
5  *
6  * Copyright (C) 2002 Roman Dementiev <[email protected]>
7  * Copyright (C) 2008-2010 Andreas Beckmann <[email protected]>
8  * Copyright (C) 2009 Johannes Singler <[email protected]>
9  * Copyright (C) 2014 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_DISK_QUEUES_HEADER
17 #define FOXXLL_IO_DISK_QUEUES_HEADER
18 
19 #include <map>
20 #include <mutex>
21 
22 #include <foxxll/io/file.hpp>
23 #include <foxxll/io/iostats.hpp>
26 #include <foxxll/io/request.hpp>
30 #include <foxxll/singleton.hpp>
31 
32 namespace foxxll {
33 
34 //! \addtogroup foxxll_reqlayer
35 //! \{
36 
37 //! Encapsulates disk queues.
38 //! \remark is a singleton
39 class disk_queues : public singleton<disk_queues>
40 {
41  friend class singleton<disk_queues>;
42 
43  using disk_id_type = int64_t;
44  using request_queue_map = std::map<disk_id_type, request_queue*>;
45 
46 protected:
47  std::mutex mutex_;
48 
50 
51  disk_queues();
52 
53 public:
54  void make_queue(file* file);
55 
56  void add_request(request_ptr& req, disk_id_type disk);
57 
58  //! Cancel a request.
59  //! The specified request is canceled unless already being processed.
60  //! However, cancelation cannot be guaranteed.
61  //! Cancelled requests must still be waited for in order to ensure correct
62  //! operation.
63  //! \param req request to cancel
64  //! \param disk disk number for disk that \c req was scheduled on
65  //! \return \c true iff the request was canceled successfully
66  bool cancel_request(request_ptr& req, disk_id_type disk);
67 
69 
70  ~disk_queues();
71 
72  //! Changes requests priorities.
73  //! \param op one of:
74  //! - READ, read requests are served before write requests within a disk queue
75  //! - WRITE, write requests are served before read requests within a disk queue
76  //! - NONE, read and write requests are served by turns, alternately
78 };
79 
80 //! \}
81 
82 } // namespace foxxll
83 
84 #endif // !FOXXLL_IO_DISK_QUEUES_HEADER
85 
86 /**************************************************************************/
Interface of a request_queue to which requests can be added and canceled.
request_queue_map queues_
Definition: disk_queues.hpp:49
void make_queue(file *file)
Definition: disk_queues.cpp:39
High-performance smart pointer used as a wrapping reference counting pointer.
void set_priority_op(const request_queue::priority_op &op)
void add_request(request_ptr &req, disk_id_type disk)
Definition: disk_queues.cpp:60
request_queue * get_queue(disk_id_type disk)
std::map< disk_id_type, request_queue * > request_queue_map
Definition: disk_queues.hpp:44
bool cancel_request(request_ptr &req, disk_id_type disk)
Definition: disk_queues.cpp:87