MySQL 5.6.14 Source Code Document
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups Pages
PosixAsyncFile.hpp
1 /*
2  Copyright (C) 2007 MySQL AB, 2008 Sun Microsystems, Inc.
3  All rights reserved. Use is subject to license terms.
4 
5  This program is free software; you can redistribute it and/or modify
6  it under the terms of the GNU General Public License as published by
7  the Free Software Foundation; version 2 of the License.
8 
9  This program is distributed in the hope that it will be useful,
10  but WITHOUT ANY WARRANTY; without even the implied warranty of
11  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12  GNU General Public License for more details.
13 
14  You should have received a copy of the GNU General Public License
15  along with this program; if not, write to the Free Software
16  Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
17 */
18 
19 #ifndef PosixAsyncFile_H
20 #define PosixAsyncFile_H
21 
28 #include <ndbzio.h>
29 
34 #ifdef HAVE_BROKEN_PREAD
35 #undef HAVE_PWRITE
36 #undef HAVE_PREAD
37 #elif defined (HAVE_PREAD)
38 #define HAVE_PWRITE
39 #endif
40 
41 class PosixAsyncFile : public AsyncFile
42 {
43  friend class Ndbfs;
44 public:
46  virtual ~PosixAsyncFile();
47 
48  virtual int init();
49  virtual bool isOpen();
50 
51  virtual void openReq(Request *request);
52  virtual void readvReq(Request *request);
53 
54  virtual void closeReq(Request *request);
55  virtual void syncReq(Request *request);
56  virtual void removeReq(Request *request);
57  virtual void appendReq(Request *request);
58  virtual void rmrfReq(Request *request, const char * path, bool removePath);
59 
60  virtual int readBuffer(Request*, char * buf, size_t size, off_t offset);
61  virtual int writeBuffer(const char * buf, size_t size, off_t offset);
62 
63  virtual void createDirectories();
64 
65 private:
66  int theFd;
67 
68  int use_gz;
69  ndbzio_stream nzf;
70  struct ndbz_alloc_rec nz_mempool;
71  void* nzfBufferUnaligned;
72 
73  int check_odirect_read(Uint32 flags, int&new_flags, int mode);
74  int check_odirect_write(Uint32 flags, int&new_flags, int mode);
75 
76 #ifndef HAVE_PREAD
77  struct FileGuard;
78  friend struct FileGuard;
79  NdbMutex * m_mutex;
80  void init_mutex() { m_mutex = NdbMutex_Create();}
81  void destroy_mutex() { NdbMutex_Destroy(m_mutex);}
82 
86  struct FileGuard
87  {
88  PosixAsyncFile* m_file;
89  FileGuard (PosixAsyncFile* file) : m_file(file) {
90  if (m_file->getThread() == 0)
91  {
92  NdbMutex_Lock(m_file->m_mutex);
93  }
94  }
95  ~FileGuard() {
96  if (m_file->getThread() == 0)
97  {
98  NdbMutex_Unlock(m_file->m_mutex);
99  }
100  }
101  };
102 #else
103  void init_mutex() {}
104  void destroy_mutex() {}
105  struct FileGuard
106  {
107  FileGuard (PosixAsyncFile* file){}
108  ~FileGuard () {}
109  };
110 #endif
111 };
112 
113 #endif