forked from pixelsdb/pixels
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathMemoryMappedFile.h
271 lines (233 loc) · 5.55 KB
/
MemoryMappedFile.h
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
/*
* Copyright 2019 PixelsDB.
*
* This file is part of Pixels.
*
* Pixels is free software: you can redistribute it and/or modify
* it under the terms of the Affero GNU General Public License as
* published by the Free Software Foundation, either version 3 of
* the License, or (at your option) any later version.
*
* Pixels is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* Affero GNU General Public License for more details.
*
* You should have received a copy of the Affero GNU General Public
* License along with Pixels. If not, see
* <https://www.gnu.org/licenses/>.
*/
#ifndef MemoryMappedFile_H
#define MemoryMappedFile_H
#include <string>
#include <sys/mman.h>
#include <sys/stat.h>
#include <fcntl.h>
#include <stdlib.h>
#include <unistd.h>
using namespace std;
typedef char byte;
class MemoryMappedFile
{
private:
static int BYTE_ARRAY_OFFSET;
int _fd;
struct stat _st;
char *_mapped;
long _size;
string _location;
static inline long roundTo4096(long i)
{
return (i + 0xfffL) & ~0xfffL;
}
void mapAndSetOffset();
public:
/**
* Constructs a new memory mapped file.
*
* @param location the file name
* @param size the file length
*/
MemoryMappedFile(string &location, long size) : _location(location), _size(roundTo4096(size))
{
mapAndSetOffset();
}
~MemoryMappedFile()
{
unmap();
}
void unmap()
{
munmap(_mapped, _st.st_size);
}
/**
* Reads a byte from the specified position.
*
* @param pos the position in the memory mapped file
* @return the value read
*/
byte getByte(long pos)
{
return 0;
}
/**
* Reads a byte (volatile) from the specified position.
*
* @param pos the position in the memory mapped file
* @return the value read
*/
byte getByteVolatile(long pos)
{
return 0;
}
short getShort(long pos)
{
return 0;
}
short getShortVolatile(long pos)
{
return 0;
}
/**
* Reads an int from the specified position.
*
* @param pos the position in the memory mapped file
* @return the value read
*/
int getInt(long pos)
{
return 0;
}
/**
* Reads an int (volatile) from the specified position.
*
* @param pos position in the memory mapped file
* @return the value read
*/
int getIntVolatile(long pos)
{
return 0;
}
/**
* Reads a long from the specified position.
*
* @param pos position in the memory mapped file
* @return the value read
*/
long getLong(long pos)
{
return 0;
}
/**
* Reads a long (volatile) from the specified position.
*
* @param pos position in the memory mapped file
* @return the value read
*/
long getLongVolatile(long pos)
{
return 0;
}
/**
* Writes a byte to the specified position.
*
* @param pos the position in the memory mapped file
* @param val the value to write
*/
void putByte(long pos, byte val)
{
}
void putBytes(long pos, byte* val, int length)
{
for (int i = 0; i < length ; ++i)
{
}
}
/**
* Writes a byte (volatile) to the specified position.
*
* @param pos the position in the memory mapped file
* @param val the value to write
*/
void putByteVolatile(long pos, byte val)
{
}
void putShort(long pos, short val)
{
}
void putShortVolatile(long pos, short val)
{
}
/**
* Writes an int to the specified position.
*
* @param pos the position in the memory mapped file
* @param val the value to write
*/
void putInt(long pos, int val)
{
}
/**
* Writes an int (volatile) to the specified position.
*
* @param pos the position in the memory mapped file
* @param val the value to write
*/
void putIntVolatile(long pos, int val)
{
}
/**
* Writes a long to the specified position.
*
* @param pos the position in the memory mapped file
* @param val the value to write
*/
void putLong(long pos, long val)
{
}
/**
* Writes a long (volatile) to the specified position.
*
* @param pos the position in the memory mapped file
* @param val the value to write
*/
void putLongVolatile(long pos, long val)
{
}
/**
* Reads a buffer of data.
*
* @param pos the position in the memory mapped file
* @param data the input buffer
* @param offset the offset in the buffer of the first byte to read data into
* @param length the length of the data
*/
void getBytes(long pos, byte* data, int offset, int length)
{
}
/**
* Writes a buffer of data.
*
* @param pos the position in the memory mapped file
* @param data the output buffer
* @param offset the offset in the buffer of the first byte to write
* @param length the length of the data
*/
void setBytes(long pos, byte* data, int offset, int length)
{
}
bool compareAndSwapInt(long pos, int expected, int value)
{
}
bool compareAndSwapLong(long pos, long expected, long value)
{
}
long getAndAddLong(long pos, long delta)
{
}
long getSize()
{
return _size;
}
};
#endif