STXXL  1.4.1
 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 
30 
31 //! \addtogroup fileimpl
32 //! \{
33 
34 //! Implementation of file based on buffered writes and block remapping via a
35 //! translation layer.
37 {
38  typedef std::pair<offset_type, offset_type> place;
39  typedef std::map<offset_type, offset_type> sortseq;
40  typedef std::map<offset_type, place> place_map;
41 
42  // the physical disk used as backend
46 
48  // logical to physical address translation
50  // physical to (logical address, size) translation
52  // list of free (physical) regions
55 
56  // the write buffers:
57  // write_buffer[curbuf] is the current write buffer
58  // write_buffer[1-curbuf] is the previous write buffer
59  // buffer_address if the start offset on the backend file
60  // curpos is the next writing position in write_buffer[curbuf]
62  char* write_buffer[2];
63  offset_type buffer_address[2];
64  int curbuf;
67 
68  struct FirstFit : public std::binary_function<place, offset_type, bool>
69  {
70  bool operator () (
71  const place& entry,
72  const offset_type size) const
73  {
74  return (entry.second >= size);
75  }
76  };
77 
78 public:
79  //! Constructs file object.
80  //! param backend_file file object used as storage backend, will be deleted in ~wbtl_file()
81  wbtl_file(
82  file* backend_file,
83  size_type write_buffer_size,
84  int write_buffers = 2,
85  int queue_id = DEFAULT_QUEUE,
86  int allocator_id = NO_ALLOCATOR);
87  ~wbtl_file();
88  offset_type size();
89  void set_size(offset_type newsize);
90  void lock();
91  void serve(void* buffer, offset_type offset, size_type bytes,
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
std::map< offset_type, place > place_map
Definition: wbtl_file.h:40
std::pair< offset_type, offset_type > place
Definition: wbtl_file.h:38
sortseq address_mapping
Definition: wbtl_file.h:49
size_type curpos
Definition: wbtl_file.h:65
mutex mapping_mutex
Definition: wbtl_file.h:47
std::map< offset_type, offset_type > sortseq
Definition: wbtl_file.h:39
request::size_type size_type
the size of a request
Definition: file.h:62
Defines interface of file.
Definition: file.h:56
file * storage
Definition: wbtl_file.h:43
size_type write_block_size
Definition: wbtl_file.h:45
#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:66
mutex buffer_mutex
Definition: wbtl_file.h:61
offset_type free_bytes
Definition: wbtl_file.h:54
offset_type sz
Definition: wbtl_file.h:44
place_map reverse_mapping
Definition: wbtl_file.h:51
Implementation of file based on buffered writes and block remapping via a translation layer...
Definition: wbtl_file.h:36
static const size_t bytes
number of bytes in uint_pair
Definition: uint_types.h:96
request::offset_type offset_type
the offset of a request, also the size of the file
Definition: file.h:60
void discard(StreamAlgorithm &in)
Reads stream content and discards it. Useful where you do not need the processed stream anymore...
Definition: stream.h:640
sortseq free_space
Definition: wbtl_file.h:53
#define STXXL_END_NAMESPACE
Definition: namespace.h:17