STXXL  1.4.0
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups Pages
request.cpp
Go to the documentation of this file.
1 /***************************************************************************
2  * lib/io/request.cpp
3  *
4  * Part of the STXXL. See http://stxxl.sourceforge.net
5  *
6  * Copyright (C) 2008 Andreas Beckmann <[email protected]>
7  * Copyright (C) 2009 Johannes Singler <[email protected]>
8  *
9  * Distributed under the Boost Software License, Version 1.0.
10  * (See accompanying file LICENSE_1_0.txt or copy at
11  * http://www.boost.org/LICENSE_1_0.txt)
12  **************************************************************************/
13 
14 #include <ostream>
15 
16 #include <stxxl/bits/io/request.h>
17 #include <stxxl/bits/io/file.h>
18 
19 
21 
22 request::request(const completion_handler& on_compl,
23  file* file__,
24  void* buffer_,
25  offset_type offset_,
26  size_type bytes_,
27  request_type type_) :
28  on_complete(on_compl),
29  file_(file__),
30  buffer(buffer_),
31  offset(offset_),
32  bytes(bytes_),
33  type(type_)
34 {
35  STXXL_VERBOSE3("[" << static_cast<void*>(this) << "] request::(...), ref_cnt=" << get_reference_count());
37 }
38 
40 {
41  STXXL_VERBOSE3("[" << static_cast<void*>(this) << "] request::~(), ref_cnt=" << get_reference_count());
42 }
43 
45 {
46  on_complete(this);
49  file_ = 0;
50 }
51 
53 {
54  if (offset % BLOCK_ALIGN != 0)
55  STXXL_ERRMSG("Offset is not aligned: modulo " <<
56  BLOCK_ALIGN << " = " << offset % BLOCK_ALIGN);
57 
58  if (bytes % BLOCK_ALIGN != 0)
59  STXXL_ERRMSG("Size is not a multiple of " <<
60  BLOCK_ALIGN << ", = " << bytes % BLOCK_ALIGN);
61 
62  if (unsigned_type(buffer) % BLOCK_ALIGN != 0)
63  STXXL_ERRMSG("Buffer is not aligned: modulo " <<
64  BLOCK_ALIGN << " = " << unsigned_type(buffer) % BLOCK_ALIGN <<
65  " (" << buffer << ")");
66 }
67 
69 {
70  STXXL_ERRMSG("WARNING: serious error, reference to the request is lost " <<
71  (after ? "after " : "before") << " serve" <<
72  " nref=" << get_reference_count() <<
73  " this=" << this <<
74  " offset=" << offset <<
75  " buffer=" << buffer <<
76  " bytes=" << bytes <<
77  " type=" << ((type == READ) ? "READ" : "WRITE") <<
78  " file=" << get_file() <<
79  " iotype=" << get_file()->io_type()
80  );
81 }
82 
83 std::ostream& request::print(std::ostream& out) const
84 {
85  out << "File object address: " << static_cast<void*>(get_file());
86  out << " Buffer address: " << static_cast<void*>(get_buffer());
87  out << " File offset: " << get_offset();
88  out << " Transfer size: " << get_size() << " bytes";
89  out << " Type of transfer: " << ((get_type() == READ) ? "READ" : "WRITE");
90  return out;
91 }
92 
94 // vim: et:ts=4:sw=4
static const int bytes
number of bytes in uint_pair
Definition: uint_types.h:99
virtual ~request()
Definition: request.cpp:39
offset_type offset
Definition: request.h:48
Completion handler class (Loki-style).
request_type type
Definition: request.h:50
offset_type get_offset() const
Definition: request.h:66
void completed()
Definition: request.cpp:44
Defines interface of file.
Definition: file.h:52
void check_nref_failed(bool after)
Definition: request.cpp:68
#define STXXL_VERBOSE3(x)
Definition: verbose.h:113
#define BLOCK_ALIGN
Definition: request.h:34
virtual const char * io_type() const =0
Identifies the type of I/O implementation.
void check_alignment() const
Definition: request.cpp:52
size_type bytes
Definition: request.h:49
#define STXXL_BEGIN_NAMESPACE
Definition: namespace.h:16
completion_handler on_complete
Definition: request.h:42
size_type get_size() const
Definition: request.h:67
void add_request_ref()
Definition: file.h:110
stxxl::internal_size_type size_type
#define STXXL_ERRMSG(x)
Definition: verbose.h:79
file * file_
Definition: request.h:46
request_type get_type() const
Definition: request.h:68
choose_int_types< my_pointer_size >::unsigned_type unsigned_type
Definition: types.h:67
std::ostream & print(std::ostream &out) const
Dumps properties of a request.
Definition: request.cpp:83
void * get_buffer() const
Definition: request.h:65
void * buffer
Definition: request.h:47
stxxl::external_size_type offset_type
unsigned_type get_reference_count() const
Return the number of references to this object (for debugging)
Definition: counting_ptr.h:510
file * get_file() const
Definition: request.h:64
void delete_request_ref()
Definition: file.h:116
#define STXXL_END_NAMESPACE
Definition: namespace.h:17
virtual void notify_waiters()=0