Stxxl  1.4.0
io/request_with_state.cpp
Go to the documentation of this file.
00001 /***************************************************************************
00002  *  io/request_with_state.cpp
00003  *
00004  *  Part of the STXXL. See http://stxxl.sourceforge.net
00005  *
00006  *  Copyright (C) 2002, 2005, 2008 Roman Dementiev <dementiev@mpi-sb.mpg.de>
00007  *  Copyright (C) 2008 Andreas Beckmann <beckmann@cs.uni-frankfurt.de>
00008  *  Copyright (C) 2009 Johannes Singler <singler@ira.uka.de>
00009  *
00010  *  Distributed under the Boost Software License, Version 1.0.
00011  *  (See accompanying file LICENSE_1_0.txt or copy at
00012  *  http://www.boost.org/LICENSE_1_0.txt)
00013  **************************************************************************/
00014 
00015 #include <stxxl/bits/io/request_with_state.h>
00016 #include <stxxl/bits/io/file.h>
00017 #include <stxxl/bits/io/disk_queues.h>
00018 
00019 __STXXL_BEGIN_NAMESPACE
00020 
00021 
00022 request_with_state::~request_with_state()
00023 {
00024     STXXL_VERBOSE3("[" << static_cast<void *>(this) << "] request_with_state::~(), ref_cnt: " << ref_cnt);
00025 
00026     assert(_state() == DONE || _state() == READY2DIE);
00027 
00028     // if(_state() != DONE && _state()!= READY2DIE )
00029     // STXXL_ERRMSG("WARNING: serious stxxl inconsistency: Request is being deleted while I/O not finished. "<<
00030     //              "Please submit a bug report.");
00031 
00032     // _state.wait_for (READY2DIE); // does not make sense ?
00033 }
00034 
00035 void request_with_state::wait(bool measure_time)
00036 {
00037     STXXL_VERBOSE3("[" << static_cast<void *>(this) << "] request_with_state::wait()");
00038 
00039     stats::scoped_wait_timer wait_timer(get_type() == READ ? stats::WAIT_OP_READ : stats::WAIT_OP_WRITE, measure_time);
00040 
00041     _state.wait_for(READY2DIE);
00042 
00043     check_errors();
00044 }
00045 
00046 bool request_with_state::cancel()
00047 {
00048     STXXL_VERBOSE3("[" << static_cast<void *>(this) << "] request_with_state::cancel() " << file_ << " " << buffer << " " << offset);
00049 
00050     if (file_)
00051     {
00052         request_ptr rp(this);
00053         if (disk_queues::get_instance()->cancel_request(rp, file_->get_queue_id()))
00054         {
00055             _state.set_to(DONE);
00056             notify_waiters();
00057             file_->delete_request_ref();
00058             file_ = 0;
00059             _state.set_to(READY2DIE);
00060             return true;
00061         }
00062     }
00063     return false;
00064 }
00065 
00066 bool request_with_state::poll()
00067 {
00068     const request_state s = _state();
00069 
00070     check_errors();
00071 
00072     return s == DONE || s == READY2DIE;
00073 }
00074 
00075 __STXXL_END_NAMESPACE
00076 // vim: et:ts=4:sw=4
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Defines