STXXL  1.4-dev
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups Pages
request_with_state.cpp
Go to the documentation of this file.
1 /***************************************************************************
2  * lib/io/request_with_state.cpp
3  *
4  * Part of the STXXL. See http://stxxl.sourceforge.net
5  *
6  * Copyright (C) 2002, 2005, 2008 Roman Dementiev <[email protected]>
7  * Copyright (C) 2008 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 
17 #include <stxxl/bits/io/file.h>
18 #include <stxxl/bits/io/iostats.h>
19 #include <stxxl/bits/io/request.h>
21 #include <stxxl/bits/singleton.h>
22 #include <stxxl/bits/verbose.h>
23 
24 #include <cassert>
25 
27 
28 request_with_state::~request_with_state()
29 {
30  STXXL_VERBOSE3_THIS("request_with_state::~(), ref_cnt: " << get_reference_count());
31 
32  assert(m_state() == DONE || m_state() == READY2DIE);
33 
34  // if(m_state() != DONE && m_state()!= READY2DIE )
35  // STXXL_ERRMSG("WARNING: serious stxxl inconsistency: Request is being deleted while I/O not finished. "<<
36  // "Please submit a bug report.");
37 
38  // m_state.wait_for (READY2DIE); // does not make sense ?
39 }
40 
41 void request_with_state::wait(bool measure_time)
42 {
43  STXXL_VERBOSE3_THIS("request_with_state::wait()");
44 
45  stats::scoped_wait_timer wait_timer(m_type == READ ? stats::WAIT_OP_READ : stats::WAIT_OP_WRITE, measure_time);
46 
47  m_state.wait_for(READY2DIE);
48 
49  check_errors();
50 }
51 
52 bool request_with_state::cancel()
53 {
54  STXXL_VERBOSE3_THIS("request_with_state::cancel() " << m_file << " " << m_buffer << " " << m_offset);
55 
56  if (m_file)
57  {
58  request_ptr rp(this);
59  if (disk_queues::get_instance()->cancel_request(rp, m_file->get_queue_id()))
60  {
61  m_state.set_to(DONE);
62  notify_waiters();
63  m_file->delete_request_ref();
64  m_file = 0;
65  m_state.set_to(READY2DIE);
66  return true;
67  }
68  }
69  return false;
70 }
71 
72 bool request_with_state::poll()
73 {
74  const request_state s = m_state();
75 
76  check_errors();
77 
78  return s == DONE || s == READY2DIE;
79 }
80 
81 void request_with_state::completed(bool canceled)
82 {
83  STXXL_VERBOSE3_THIS("request_with_state::completed()");
84  m_state.set_to(DONE);
85  if (!canceled)
86  m_on_complete(this);
87  notify_waiters();
88  m_file->delete_request_ref();
89  m_file = 0;
90  m_state.set_to(READY2DIE);
91 }
92 
94 
95 // vim: et:ts=4:sw=4
#define STXXL_BEGIN_NAMESPACE
Definition: namespace.h:16
#define STXXL_VERBOSE3_THIS(x)
Definition: verbose.h:142
request_state
states of request OP - operating, DONE - request served, READY2DIE - can be destroyed ...
#define STXXL_END_NAMESPACE
Definition: namespace.h:17