Stxxl  1.2.1
boostfd_file.h
1 /***************************************************************************
2  * include/stxxl/bits/io/boostfd_file.h
3  *
4  * File implementation based on boost::iostreams::file_decriptor
5  *
6  * Part of the STXXL. See http://stxxl.sourceforge.net
7  *
8  * Copyright (C) 2006 Roman Dementiev <dementiev@ira.uka.de>
9  *
10  * Distributed under the Boost Software License, Version 1.0.
11  * (See accompanying file LICENSE_1_0.txt or copy at
12  * http://www.boost.org/LICENSE_1_0.txt)
13  **************************************************************************/
14 
15 #ifndef STXXL_BOOSTFD_FILE_H_
16 #define STXXL_BOOSTFD_FILE_H_
17 
18 #ifdef STXXL_BOOST_CONFIG // if boost is available
19 
20  #include <stxxl/bits/io/iobase.h>
21 
22  #include <boost/iostreams/device/file_descriptor.hpp>
23 
24 
25 __STXXL_BEGIN_NAMESPACE
26 
29 
30 class boostfd_request;
31 
33 class boostfd_file : public file
34 {
35 public:
36  typedef boost::iostreams::file_descriptor fd_type;
37 
38 protected:
39  fd_type file_des;
40  int mode_;
41 
42 public:
43  boostfd_file(const std::string & filename, int mode, int disk = -1);
44  fd_type get_file_des() const;
45  ~boostfd_file();
46  stxxl::int64 size();
47  void set_size(stxxl::int64 newsize);
49  void * buffer,
50  stxxl::int64 pos,
51  size_t bytes,
52  completion_handler on_cmpl);
54  void * buffer,
55  stxxl::int64 pos,
56  size_t bytes,
57  completion_handler on_cmpl);
58 };
59 
61 class boostfd_request : public request
62 {
63  friend class boostfd_file;
64 
65 protected:
66  // states of request
67  enum { OP = 0, DONE = 1, READY2DIE = 2 }; // OP - operating, DONE - request served,
68  // READY2DIE - can be destroyed
69 
70  state _state;
71  mutex waiters_mutex;
72  std::set<onoff_switch *> waiters;
73 
74  boostfd_request(
75  boostfd_file * f,
76  void * buf,
77  stxxl::int64 off,
78  size_t b,
79  request_type t,
80  completion_handler on_cmpl);
81 
82  bool add_waiter(onoff_switch * sw);
83  void delete_waiter(onoff_switch * sw);
84  int nwaiters(); // returns the number of waiters
85  void check_aligning();
86  void serve();
87 
88 public:
89  virtual ~boostfd_request();
90  void wait();
91  bool poll();
92  const char * io_type();
93 };
94 
96 
97 __STXXL_END_NAMESPACE
98 
99 #endif // #ifdef STXXL_BOOST_CONFIG
100 
101 #endif // !STXXL_BOOSTFD_FILE_H_