Stxxl
1.2.1
|
00001 /*************************************************************************** 00002 * include/stxxl/bits/io/boostfd_file.h 00003 * 00004 * File implementation based on boost::iostreams::file_decriptor 00005 * 00006 * Part of the STXXL. See http://stxxl.sourceforge.net 00007 * 00008 * Copyright (C) 2006 Roman Dementiev <dementiev@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 #ifndef STXXL_BOOSTFD_FILE_H_ 00016 #define STXXL_BOOSTFD_FILE_H_ 00017 00018 #ifdef STXXL_BOOST_CONFIG // if boost is available 00019 00020 #include <stxxl/bits/io/iobase.h> 00021 00022 #include <boost/iostreams/device/file_descriptor.hpp> 00023 00024 00025 __STXXL_BEGIN_NAMESPACE 00026 00029 00030 class boostfd_request; 00031 00033 class boostfd_file : public file 00034 { 00035 public: 00036 typedef boost::iostreams::file_descriptor fd_type; 00037 00038 protected: 00039 fd_type file_des; 00040 int mode_; 00041 00042 public: 00043 boostfd_file(const std::string & filename, int mode, int disk = -1); 00044 fd_type get_file_des() const; 00045 ~boostfd_file(); 00046 stxxl::int64 size(); 00047 void set_size(stxxl::int64 newsize); 00048 request_ptr aread( 00049 void * buffer, 00050 stxxl::int64 pos, 00051 size_t bytes, 00052 completion_handler on_cmpl); 00053 request_ptr awrite( 00054 void * buffer, 00055 stxxl::int64 pos, 00056 size_t bytes, 00057 completion_handler on_cmpl); 00058 }; 00059 00061 class boostfd_request : public request 00062 { 00063 friend class boostfd_file; 00064 00065 protected: 00066 // states of request 00067 enum { OP = 0, DONE = 1, READY2DIE = 2 }; // OP - operating, DONE - request served, 00068 // READY2DIE - can be destroyed 00069 00070 state _state; 00071 mutex waiters_mutex; 00072 std::set<onoff_switch *> waiters; 00073 00074 boostfd_request( 00075 boostfd_file * f, 00076 void * buf, 00077 stxxl::int64 off, 00078 size_t b, 00079 request_type t, 00080 completion_handler on_cmpl); 00081 00082 bool add_waiter(onoff_switch * sw); 00083 void delete_waiter(onoff_switch * sw); 00084 int nwaiters(); // returns the number of waiters 00085 void check_aligning(); 00086 void serve(); 00087 00088 public: 00089 virtual ~boostfd_request(); 00090 void wait(); 00091 bool poll(); 00092 const char * io_type(); 00093 }; 00094 00096 00097 __STXXL_END_NAMESPACE 00098 00099 #endif // #ifdef STXXL_BOOST_CONFIG 00100 00101 #endif // !STXXL_BOOSTFD_FILE_H_