Thrill  0.1
disk_queues.cpp
Go to the documentation of this file.
1 /***************************************************************************
2  * foxxll/io/disk_queues.cpp
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 
17 
18 #include <foxxll/io/iostats.hpp>
23 
24 namespace foxxll {
25 
27 {
28  stats::get_instance(); // initialize stats before ourselves
29 }
30 
32 {
33  std::unique_lock<std::mutex> lock(mutex_);
34  // deallocate all queues_
35  for (request_queue_map::iterator i = queues_.begin(); i != queues_.end(); i++)
36  delete (*i).second;
37 }
38 
40 {
41  std::unique_lock<std::mutex> lock(mutex_);
42 
43  int queue_id = file->get_queue_id();
44 
45  request_queue_map::iterator qi = queues_.find(queue_id);
46  if (qi != queues_.end())
47  return;
48 
49  // create new request queue
50 #if FOXXLL_HAVE_LINUXAIO_FILE
51  if (const linuxaio_file* af =
52  dynamic_cast<const linuxaio_file*>(file)) {
53  queues_[queue_id] = new linuxaio_queue(af->get_desired_queue_length());
54  return;
55  }
56 #endif
57  queues_[queue_id] = new request_queue_impl_qwqr();
58 }
59 
61 {
62  std::unique_lock<std::mutex> lock(mutex_);
63 
64 #ifdef FOXXLL_HACK_SINGLE_IO_THREAD
65  disk = 42;
66 #endif
67  request_queue_map::iterator qi = queues_.find(disk);
68  request_queue* q;
69  if (qi == queues_.end())
70  {
71  // create new request queue
72 #if FOXXLL_HAVE_LINUXAIO_FILE
73  if (dynamic_cast<linuxaio_request*>(req.get()))
74  q = queues_[disk] = new linuxaio_queue(
75  dynamic_cast<linuxaio_file*>(req->get_file())->get_desired_queue_length()
76  );
77  else
78 #endif
79  q = queues_[disk] = new request_queue_impl_qwqr();
80  }
81  else
82  q = qi->second;
83 
84  q->add_request(req);
85 }
86 
88 {
89  std::unique_lock<std::mutex> lock(mutex_);
90 
91 #ifdef FOXXLL_HACK_SINGLE_IO_THREAD
92  disk = 42;
93 #endif
94  if (queues_.find(disk) != queues_.end())
95  return queues_[disk]->cancel_request(req);
96  else
97  return false;
98 }
99 
101 {
102  std::unique_lock<std::mutex> lock(mutex_);
103 
104  if (queues_.find(disk) != queues_.end())
105  return queues_[disk];
106  else
107  return nullptr;
108 }
109 
111 {
112  std::unique_lock<std::mutex> lock(mutex_);
113 
114  for (request_queue_map::iterator i = queues_.begin(); i != queues_.end(); i++)
115  i->second->set_priority_op(op);
116 }
117 
118 } // namespace foxxll
119 
120 /**************************************************************************/
Interface of a request_queue to which requests can be added and canceled.
virtual void add_request(request_ptr &req)=0
request_queue_map queues_
Definition: disk_queues.hpp:49
virtual int get_queue_id() const =0
Type * get() const noexcept
return the enclosed pointer.
FOXXLL library namespace
void make_queue(file *file)
Definition: disk_queues.cpp:39
static instance_pointer get_instance()
return instance or create base instance if empty
Definition: singleton.hpp:41
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)
bool cancel_request(request_ptr &req, disk_id_type disk)
Definition: disk_queues.cpp:87