STXXL  1.4.0
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups Pages
wbtl_file.h
Go to the documentation of this file.
1 /***************************************************************************
2  * include/stxxl/bits/io/wbtl_file.h
3  *
4  * a write-buffered-translation-layer pseudo file
5  *
6  * Part of the STXXL. See http://stxxl.sourceforge.net
7  *
8  * Copyright (C) 2008-2009 Andreas Beckmann <[email protected]>
9  * Copyright (C) 2009 Johannes Singler <[email protected]>
10  *
11  * Distributed under the Boost Software License, Version 1.0.
12  * (See accompanying file LICENSE_1_0.txt or copy at
13  * http://www.boost.org/LICENSE_1_0.txt)
14  **************************************************************************/
15 
16 #ifndef STXXL_IO_WBTL_FILE_HEADER
17 #define STXXL_IO_WBTL_FILE_HEADER
18 
19 #ifndef STXXL_HAVE_WBTL_FILE
20 #define STXXL_HAVE_WBTL_FILE 1
21 #endif
22 
23 #if STXXL_HAVE_WBTL_FILE
24 
25 #include <map>
26 
28 
29 
31 
32 //! \addtogroup fileimpl
33 //! \{
34 
35 //! Implementation of file based on buffered writes and block remapping via a
36 //! translation layer.
38 {
39  typedef std::pair<offset_type, offset_type> place;
40  typedef std::map<offset_type, offset_type> sortseq;
41  typedef std::map<offset_type, place> place_map;
42 
43  // the physical disk used as backend
47 
49  // logical to physical address translation
51  // physical to (logical address, size) translation
53  // list of free (physical) regions
56 
57  // the write buffers:
58  // write_buffer[curbuf] is the current write buffer
59  // write_buffer[1-curbuf] is the previous write buffer
60  // buffer_address if the start offset on the backend file
61  // curpos is the next writing position in write_buffer[curbuf]
63  char* write_buffer[2];
64  offset_type buffer_address[2];
65  int curbuf;
68 
69  struct FirstFit : public std::binary_function<place, offset_type, bool>
70  {
71  bool operator () (
72  const place& entry,
73  const offset_type size) const
74  {
75  return (entry.second >= size);
76  }
77  };
78 
79 public:
80  //! Constructs file object.
81  //! param backend_file file object used as storage backend, will be deleted in ~wbtl_file()
82  wbtl_file(
83  file* backend_file,
84  size_type write_buffer_size,
85  int write_buffers = 2,
86  int queue_id = DEFAULT_QUEUE,
87  int allocator_id = NO_ALLOCATOR);
88  ~wbtl_file();
89  offset_type size();
90  void set_size(offset_type newsize);
91  void lock();
92  void serve(const request* req) throw (io_error);
93  void discard(offset_type offset, offset_type size);
94  const char * io_type() const;
95 
96 private:
97  void _add_free_region(offset_type offset, offset_type size);
98 
99 protected:
100  void sread(void* buffer, offset_type offset, size_type bytes);
101  void swrite(void* buffer, offset_type offset, size_type bytes);
102  offset_type get_next_write_block();
103  void check_corruption(offset_type region_pos, offset_type region_size,
104  sortseq::iterator pred, sortseq::iterator succ);
105 };
106 
107 //! \}
108 
110 
111 #endif // #if STXXL_HAVE_WBTL_FILE
112 
113 #endif // !STXXL_IO_WBTL_FILE_HEADER
static const int bytes
number of bytes in uint_pair
Definition: uint_types.h:99
std::map< offset_type, place > place_map
Definition: wbtl_file.h:41
std::pair< offset_type, offset_type > place
Definition: wbtl_file.h:39
sortseq address_mapping
Definition: wbtl_file.h:50
size_type curpos
Definition: wbtl_file.h:66
mutex mapping_mutex
Definition: wbtl_file.h:48
std::map< offset_type, offset_type > sortseq
Definition: wbtl_file.h:40
request::size_type size_type
the size of a request
Definition: file.h:66
Defines interface of file.
Definition: file.h:52
file * storage
Definition: wbtl_file.h:44
size_type write_block_size
Definition: wbtl_file.h:46
#define STXXL_BEGIN_NAMESPACE
Definition: namespace.h:16
Implementation of some file methods based on serving_request.
request_ptr backend_request
Definition: wbtl_file.h:67
mutex buffer_mutex
Definition: wbtl_file.h:62
offset_type free_bytes
Definition: wbtl_file.h:55
offset_type sz
Definition: wbtl_file.h:45
place_map reverse_mapping
Definition: wbtl_file.h:52
Implementation of file based on buffered writes and block remapping via a translation layer...
Definition: wbtl_file.h:37
void discard(StreamAlgorithm_ &in)
Reads stream content and discards it. Useful where you do not need the processed stream anymore...
Definition: stream.h:606
request::offset_type offset_type
the offset of a request, also the size of the file
Definition: file.h:64
Request with basic properties like file and offset.
Definition: request.h:39
sortseq free_space
Definition: wbtl_file.h:54
#define STXXL_END_NAMESPACE
Definition: namespace.h:17