STXXL  1.4.0
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups Pages
disk_queues.h
Go to the documentation of this file.
1 /***************************************************************************
2  * include/stxxl/bits/io/disk_queues.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-2010 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 STXXL_IO_DISK_QUEUES_HEADER
16 #define STXXL_IO_DISK_QUEUES_HEADER
17 
18 #include <map>
19 
20 #include <stxxl/bits/namespace.h>
21 #include <stxxl/bits/singleton.h>
22 #include <stxxl/bits/io/iostats.h>
23 #include <stxxl/bits/io/request.h>
25 
26 
28 
29 //! \addtogroup iolayer
30 //! \{
31 
32 //! Encapsulates disk queues.
33 //! \remark is a singleton
34 class disk_queues : public singleton<disk_queues>
35 {
36  friend class singleton<disk_queues>;
37 
38  // 2 queues: write queue and read queue
40 
42  typedef std::map<DISKID, request_queue_type*> request_queue_map;
43 
44 protected:
47  {
48  stxxl::stats::get_instance(); // initialize stats before ourselves
49  }
50 
51 public:
52  void add_request(request_ptr& req, DISKID disk)
53  {
54 #ifdef STXXL_HACK_SINGLE_IO_THREAD
55  disk = 42;
56 #endif
57  if (queues.find(disk) == queues.end())
58  {
59  // create new request queue
60  queues[disk] = new request_queue_type();
61  }
62  queues[disk]->add_request(req);
63  }
64 
65  //! Cancel a request.
66  //! The specified request is canceled unless already being processed.
67  //! However, cancelation cannot be guaranteed.
68  //! Cancelled requests must still be waited for in order to ensure correct
69  //! operation.
70  //! \param req request to cancel
71  //! \param disk disk number for disk that \c req was scheduled on
72  //! \return \c true iff the request was canceled successfully
74  {
75 #ifdef STXXL_HACK_SINGLE_IO_THREAD
76  disk = 42;
77 #endif
78  if (queues.find(disk) != queues.end())
79  return queues[disk]->cancel_request(req);
80  else
81  return false;
82  }
83 
85  {
86  // deallocate all queues
87  for (request_queue_map::iterator i = queues.begin(); i != queues.end(); i++)
88  delete (*i).second;
89  }
90 
91  //! Changes requests priorities.
92  //! \param op one of:
93  //! - READ, read requests are served before write requests within a disk queue
94  //! - WRITE, write requests are served before read requests within a disk queue
95  //! - NONE, read and write requests are served by turns, alternately
97  {
98  for (request_queue_map::iterator i = queues.begin(); i != queues.end(); i++)
99  i->second->set_priority_op(op);
100  }
101 };
102 
103 //! \}
104 
106 
107 #endif // !STXXL_IO_DISK_QUEUES_HEADER
108 // vim: et:ts=4:sw=4
request_queue_impl_qwqr request_queue_type
Definition: disk_queues.h:39
void set_priority_op(request_queue::priority_op op)
Changes requests priorities.
Definition: disk_queues.h:96
long long int int64
Definition: types.h:40
Encapsulates disk queues.
Definition: disk_queues.h:34
stxxl::int64 DISKID
Definition: disk_queues.h:41
void add_request(request_ptr &req, DISKID disk)
Definition: disk_queues.h:52
static instance_pointer get_instance()
Definition: singleton.h:39
request_queue_map queues
Definition: disk_queues.h:45
#define STXXL_BEGIN_NAMESPACE
Definition: namespace.h:16
std::map< DISKID, request_queue_type * > request_queue_map
Definition: disk_queues.h:42
bool cancel_request(request_ptr &req, DISKID disk)
Cancel a request. The specified request is canceled unless already being processed. However, cancelation cannot be guaranteed. Cancelled requests must still be waited for in order to ensure correct operation.
Definition: disk_queues.h:73
#define STXXL_END_NAMESPACE
Definition: namespace.h:17