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