• Main Page
  • Related Pages
  • Modules
  • Namespaces
  • Classes
  • Files
  • Examples
  • File List

wbtl_file.h

00001 /***************************************************************************
00002  *  include/stxxl/bits/io/wbtl_file.h
00003  *
00004  *  a write-buffered-translation-layer pseudo file
00005  *
00006  *  Part of the STXXL. See http://stxxl.sourceforge.net
00007  *
00008  *  Copyright (C) 2008-2009 Andreas Beckmann <[email protected]>
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_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     // the physical disk used as backend
00043     file * storage;
00044     offset_type sz;
00045     size_type write_block_size;
00046 
00047     mutex mapping_mutex;
00048     // logical to physical address translation
00049     sortseq address_mapping;
00050     // physical to (logical address, size) translation
00051     place_map reverse_mapping;
00052     // list of free (physical) regions
00053     sortseq free_space;
00054     offset_type free_bytes;
00055 
00056     // the write buffers:
00057     // write_buffer[curbuf] is the current write buffer
00058     // write_buffer[1-curbuf] is the previous write buffer
00059     // buffer_address if the start offset on the backend file
00060     // curpos is the next writing position in write_buffer[curbuf]
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

Generated by  doxygen 1.7.1