STXXL  1.4.0
 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 
26 
28 
29 request_with_state::~request_with_state()
30 {
31  STXXL_VERBOSE3("[" << static_cast<void*>(this) << "] request_with_state::~(), ref_cnt: " << ref_cnt);
32 
33  assert(_state() == DONE || _state() == READY2DIE);
34 
35  // if(_state() != DONE && _state()!= READY2DIE )
36  // STXXL_ERRMSG("WARNING: serious stxxl inconsistency: Request is being deleted while I/O not finished. "<<
37  // "Please submit a bug report.");
38 
39  // _state.wait_for (READY2DIE); // does not make sense ?
40 }
41 
42 void request_with_state::wait(bool measure_time)
43 {
44  STXXL_VERBOSE3("[" << static_cast<void*>(this) << "] request_with_state::wait()");
45 
46  stats::scoped_wait_timer wait_timer(get_type() == READ ? stats::WAIT_OP_READ : stats::WAIT_OP_WRITE, measure_time);
47 
48  _state.wait_for(READY2DIE);
49 
50  check_errors();
51 }
52 
53 bool request_with_state::cancel()
54 {
55  STXXL_VERBOSE3("[" << static_cast<void*>(this) << "] request_with_state::cancel() " << file_ << " " << buffer << " " << offset);
56 
57  if (file_)
58  {
59  request_ptr rp(this);
60  if (disk_queues::get_instance()->cancel_request(rp, file_->get_queue_id()))
61  {
62  _state.set_to(DONE);
63  notify_waiters();
64  file_->delete_request_ref();
65  file_ = 0;
66  _state.set_to(READY2DIE);
67  return true;
68  }
69  }
70  return false;
71 }
72 
73 bool request_with_state::poll()
74 {
75  const request_state s = _state();
76 
77  check_errors();
78 
79  return s == DONE || s == READY2DIE;
80 }
81 
83 // vim: et:ts=4:sw=4
#define STXXL_VERBOSE3(x)
Definition: verbose.h:113
#define STXXL_BEGIN_NAMESPACE
Definition: namespace.h:16
request_state
states of request OP - operating, DONE - request served, READY2DIE - can be destroyed ...
#define STXXL_END_NAMESPACE
Definition: namespace.h:17