Stxxl
1.4.0
|
00001 /*************************************************************************** 00002 * io/request.cpp 00003 * 00004 * Part of the STXXL. See http://stxxl.sourceforge.net 00005 * 00006 * Copyright (C) 2008 Andreas Beckmann <beckmann@cs.uni-frankfurt.de> 00007 * Copyright (C) 2009 Johannes Singler <singler@ira.uka.de> 00008 * 00009 * Distributed under the Boost Software License, Version 1.0. 00010 * (See accompanying file LICENSE_1_0.txt or copy at 00011 * http://www.boost.org/LICENSE_1_0.txt) 00012 **************************************************************************/ 00013 00014 #include <ostream> 00015 00016 #include <stxxl/bits/io/request.h> 00017 #include <stxxl/bits/io/file.h> 00018 00019 00020 __STXXL_BEGIN_NAMESPACE 00021 00022 request::request(const completion_handler & on_compl, 00023 file * file__, 00024 void * buffer_, 00025 offset_type offset_, 00026 size_type bytes_, 00027 request_type type_) : 00028 on_complete(on_compl), ref_cnt(0), 00029 file_(file__), 00030 buffer(buffer_), 00031 offset(offset_), 00032 bytes(bytes_), 00033 type(type_) 00034 { 00035 STXXL_VERBOSE3("[" << static_cast<void *>(this) << "] request::(...), ref_cnt=" << ref_cnt); 00036 file_->add_request_ref(); 00037 } 00038 00039 request::~request() 00040 { 00041 STXXL_VERBOSE3("[" << static_cast<void *>(this) << "] request::~(), ref_cnt=" << ref_cnt); 00042 } 00043 00044 void request::completed() 00045 { 00046 on_complete(this); 00047 notify_waiters(); 00048 file_->delete_request_ref(); 00049 file_ = 0; 00050 } 00051 00052 void request::check_alignment() const 00053 { 00054 if (offset % BLOCK_ALIGN != 0) 00055 STXXL_ERRMSG("Offset is not aligned: modulo " << 00056 BLOCK_ALIGN << " = " << offset % BLOCK_ALIGN); 00057 00058 if (bytes % BLOCK_ALIGN != 0) 00059 STXXL_ERRMSG("Size is not a multiple of " << 00060 BLOCK_ALIGN << ", = " << bytes % BLOCK_ALIGN); 00061 00062 if (unsigned_type(buffer) % BLOCK_ALIGN != 0) 00063 STXXL_ERRMSG("Buffer is not aligned: modulo " << 00064 BLOCK_ALIGN << " = " << unsigned_type(buffer) % BLOCK_ALIGN << 00065 " (" << buffer << ")"); 00066 } 00067 00068 void request::check_nref_failed(bool after) 00069 { 00070 STXXL_ERRMSG("WARNING: serious error, reference to the request is lost " << 00071 (after ? "after " : "before") << " serve" << 00072 " nref=" << nref() << 00073 " this=" << this << 00074 " offset=" << offset << 00075 " buffer=" << buffer << 00076 " bytes=" << bytes << 00077 " type=" << ((type == READ) ? "READ" : "WRITE") << 00078 " file=" << get_file() << 00079 " iotype=" << get_file()->io_type() 00080 ); 00081 } 00082 00083 std::ostream & request::print(std::ostream & out) const 00084 { 00085 out << "File object address: " << static_cast<void *>(get_file()); 00086 out << " Buffer address: " << static_cast<void *>(get_buffer()); 00087 out << " File offset: " << get_offset(); 00088 out << " Transfer size: " << get_size() << " bytes"; 00089 out << " Type of transfer: " << ((get_type() == READ) ? "READ" : "WRITE"); 00090 return out; 00091 } 00092 00093 __STXXL_END_NAMESPACE 00094 // vim: et:ts=4:sw=4