MySQL 5.6.14 Source Code Document
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups Pages
AsyncFile.hpp
1 /*
2  Copyright (c) 2003, 2010, Oracle and/or its affiliates. All rights reserved.
3 
4  This program is free software; you can redistribute it and/or modify
5  it under the terms of the GNU General Public License as published by
6  the Free Software Foundation; version 2 of the License.
7 
8  This program is distributed in the hope that it will be useful,
9  but WITHOUT ANY WARRANTY; without even the implied warranty of
10  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
11  GNU General Public License for more details.
12 
13  You should have received a copy of the GNU General Public License
14  along with this program; if not, write to the Free Software
15  Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
16 */
17 
18 #ifndef AsyncFile_H
19 #define AsyncFile_H
20 
21 #include <kernel_types.h>
22 #include "AsyncIoThread.hpp"
23 #include "Filename.hpp"
24 
25 class AsyncFile
26 {
27  friend class Ndbfs;
28  friend class AsyncIoThread;
29 
30 public:
32  virtual ~AsyncFile() {};
33 
34  virtual int init() = 0;
35  virtual bool isOpen() = 0;
36 
37  Filename theFileName;
38  Request *m_current_request, *m_last_request;
39 
40  void set_buffer(Uint32 rg, Ptr<GlobalPage> ptr, Uint32 cnt);
41  bool has_buffer() const;
42  void clear_buffer(Uint32 &rg, Ptr<GlobalPage> & ptr, Uint32 & cnt);
43 
44  AsyncIoThread* getThread() const { return m_thread;}
45 private:
46 
55  virtual void openReq(Request *request) = 0;
56 
60  virtual int readBuffer(Request*, char * buf, size_t size, off_t offset)=0;
61 
65  virtual int writeBuffer(const char * buf, size_t size, off_t offset)=0;
66 
67  virtual void closeReq(Request *request)=0;
68  virtual void syncReq(Request *request)=0;
69  virtual void removeReq(Request *request)=0;
70  virtual void appendReq(Request *request)=0;
71  virtual void rmrfReq(Request *request, const char * path, bool removePath)=0;
72  virtual void createDirectories()=0;
73 
77 protected:
78  virtual void readReq(Request *request);
79  virtual void readvReq(Request *request);
80 
85  virtual void writeReq(Request *request);
86  virtual void writevReq(Request *request);
87 
88 private:
89  void attach(AsyncIoThread* thr);
90  void detach(AsyncIoThread* thr);
91 
92  AsyncIoThread* m_thread; // For bound files
93 
94 protected:
95  size_t m_write_wo_sync; // Writes wo/ sync
96  size_t m_auto_sync_freq; // Auto sync freq in bytes
97  Uint32 m_open_flags;
98 
103  Uint32 m_page_cnt;
104  Ptr<GlobalPage> m_page_ptr;
105 
106  char* theWriteBuffer;
107  Uint32 theWriteBufferSize;
108 
109 public:
110  SimulatedBlock& m_fs;
111 };
112 
113 inline
114 void
115 AsyncFile::set_buffer(Uint32 rg, Ptr<GlobalPage> ptr, Uint32 cnt)
116 {
117  assert(!has_buffer());
118  m_resource_group = rg;
119  m_page_ptr = ptr;
120  m_page_cnt = cnt;
121  theWriteBuffer = (char*)ptr.p;
122  theWriteBufferSize = cnt * sizeof(GlobalPage);
123 }
124 
125 inline
126 bool
127 AsyncFile::has_buffer() const
128 {
129  return m_page_cnt > 0;
130 }
131 
132 inline
133 void
134 AsyncFile::clear_buffer(Uint32 & rg, Ptr<GlobalPage> & ptr, Uint32 & cnt)
135 {
136  assert(has_buffer());
137  rg = m_resource_group;
138  ptr = m_page_ptr;
139  cnt = m_page_cnt;
140  m_resource_group = RNIL;
141  m_page_cnt = 0;
142  m_page_ptr.setNull();
143  theWriteBuffer = 0;
144  theWriteBufferSize = 0;
145 }
146 
147 #endif