00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016 #ifndef STXXL_WBTL_FILE_HEADER
00017 #define STXXL_WBTL_FILE_HEADER
00018
00019 #ifndef STXXL_HAVE_WBTL_FILE
00020 #define STXXL_HAVE_WBTL_FILE 1
00021 #endif
00022
00023 #if STXXL_HAVE_WBTL_FILE
00024
00025 #include <map>
00026
00027 #include <stxxl/bits/io/disk_queued_file.h>
00028
00029
00030 __STXXL_BEGIN_NAMESPACE
00031
00034
00037 class wbtl_file : public disk_queued_file
00038 {
00039 typedef std::pair<offset_type, offset_type> place;
00040 typedef std::map<offset_type, offset_type> sortseq;
00041 typedef std::map<offset_type, place> place_map;
00042
00043
00044 file * storage;
00045 offset_type sz;
00046 size_type write_block_size;
00047
00048 mutex mapping_mutex;
00049
00050 sortseq address_mapping;
00051
00052 place_map reverse_mapping;
00053
00054 sortseq free_space;
00055 offset_type free_bytes;
00056
00057
00058
00059
00060
00061
00062 mutex buffer_mutex;
00063 char * write_buffer[2];
00064 offset_type buffer_address[2];
00065 int curbuf;
00066 size_type curpos;
00067 request_ptr backend_request;
00068
00069 struct FirstFit : public std::binary_function<place, offset_type, bool>
00070 {
00071 bool operator () (
00072 const place & entry,
00073 const offset_type size) const
00074 {
00075 return (entry.second >= size);
00076 }
00077 };
00078
00079 public:
00083 wbtl_file(
00084 file * backend_file,
00085 size_type write_buffer_size,
00086 int write_buffers = 2,
00087 int queue_id = DEFAULT_QUEUE,
00088 int allocator_id = NO_ALLOCATOR);
00089 ~wbtl_file();
00090 offset_type size();
00091 void set_size(offset_type newsize);
00092 void lock();
00093 void serve(const request * req) throw (io_error);
00094 void discard(offset_type offset, offset_type size);
00095 const char * io_type() const;
00096
00097 private:
00098 void _add_free_region(offset_type offset, offset_type size);
00099
00100 protected:
00101 void sread(void * buffer, offset_type offset, size_type bytes);
00102 void swrite(void * buffer, offset_type offset, size_type bytes);
00103 offset_type get_next_write_block();
00104 void check_corruption(offset_type region_pos, offset_type region_size,
00105 sortseq::iterator pred, sortseq::iterator succ);
00106 };
00107
00109
00110 __STXXL_END_NAMESPACE
00111
00112 #endif // #if STXXL_HAVE_WBTL_FILE
00113
00114 #endif // !STXXL_WBTL_FILE_HEADER