Thrill  0.1
linuxaio_file.hpp
Go to the documentation of this file.
1 /***************************************************************************
2  * foxxll/io/linuxaio_file.hpp
3  *
4  * Part of FOXXLL. See http://foxxll.org
5  *
6  * Copyright (C) 2011 Johannes Singler <[email protected]>
7  * Copyright (C) 2014 Timo Bingmann <[email protected]>
8  *
9  * Distributed under the Boost Software License, Version 1.0.
10  * (See accompanying file LICENSE_1_0.txt or copy at
11  * http://www.boost.org/LICENSE_1_0.txt)
12  **************************************************************************/
13 
14 #ifndef FOXXLL_IO_LINUXAIO_FILE_HEADER
15 #define FOXXLL_IO_LINUXAIO_FILE_HEADER
16 
17 #include <foxxll/config.hpp>
18 
19 #if FOXXLL_HAVE_LINUXAIO_FILE
20 
21 #include <string>
22 
26 
27 namespace foxxll {
28 
29 class linuxaio_queue;
30 
31 //! \addtogroup foxxll_fileimpl
32 //! \{
33 
34 //! Implementation of \c file based on the Linux kernel interface for
35 //! asynchronous I/O
36 class linuxaio_file final : public ufs_file_base, public disk_queued_file
37 {
38  friend class linuxaio_request;
39 
40 private:
41  int desired_queue_length_;
42 
43 public:
44  //! Constructs file object
45  //! \param filename path of file
46  //! \param mode open mode, see \c foxxll::file::open_modes
47  //! \param queue_id disk queue identifier
48  //! \param allocator_id linked disk_allocator
49  //! \param device_id physical device identifier
50  //! \param desired_queue_length queue length requested from kernel
51  linuxaio_file(
52  const std::string& filename, int mode,
53  int queue_id = DEFAULT_LINUXAIO_QUEUE,
54  int allocator_id = NO_ALLOCATOR,
55  unsigned int device_id = DEFAULT_DEVICE_ID,
56  int desired_queue_length = 0)
57  : file(device_id),
58  ufs_file_base(filename, mode),
59  disk_queued_file(queue_id, allocator_id),
60  desired_queue_length_(desired_queue_length)
61  { }
62 
63  void serve(void* buffer, offset_type offset, size_type bytes,
64  request::read_or_write op) final;
65 
66  request_ptr aread(
67  void* buffer, offset_type pos, size_type bytes,
68  const completion_handler& on_cmpl = completion_handler()) final;
69 
70  request_ptr awrite(
71  void* buffer, offset_type pos, size_type bytes,
72  const completion_handler& on_cmpl = completion_handler()) final;
73 
74  const char * io_type() const final;
75 
76  int get_desired_queue_length() const
77  { return desired_queue_length_; }
78 };
79 
80 //! \}
81 
82 } // namespace foxxll
83 
84 #endif // #if FOXXLL_HAVE_LINUXAIO_FILE
85 
86 #endif // !FOXXLL_IO_LINUXAIO_FILE_HEADER
87 
88 /**************************************************************************/
tlx::counting_ptr< request > request_ptr
A reference counting pointer for request.
Definition: request.hpp:43
tlx::delegate< void(request *r, bool success)> completion_handler
completion handler
Definition: request.hpp:46
FOXXLL library namespace
std::basic_string< char, std::char_traits< char >, Allocator< char > > string
string with Manager tracking
Definition: allocator.hpp:220
static const size_t bytes
number of bytes in uint_pair
Definition: uint_types.hpp:75