forked from ShawnZhong/MadFS
-
Notifications
You must be signed in to change notification settings - Fork 4
/
Copy pathread.cpp
36 lines (31 loc) · 955 Bytes
/
read.cpp
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
#include "tx/read.h"
#include "file/file.h"
namespace madfs::dram {
ssize_t File::pread(char* buf, size_t count, size_t offset) {
if (unlikely(!can_read)) {
errno = EBADF;
return -1;
}
if (unlikely(count == 0)) return 0;
TimerGuard<Event::READ_TX> timer_guard;
timer.start<Event::READ_TX_CTOR>();
return ReadTx(this, buf, count, offset).exec();
}
ssize_t File::read(char* buf, size_t count) {
if (unlikely(!can_read)) {
errno = EBADF;
return -1;
}
if (unlikely(count == 0)) return 0;
FileState state;
uint64_t ticket;
uint64_t offset;
blk_table.update([&](const FileState& file_state) {
offset = offset_mgr.acquire(count, file_state.file_size,
/*stop_at_boundary*/ true, ticket);
state = file_state;
});
return Tx::exec_and_release_offset<ReadTx>(this, buf, count, offset, state,
ticket);
}
} // namespace madfs::dram