mirror of
https://github.com/dashpay/dash.git
synced 2024-12-27 21:12:48 +01:00
LevelDB: use PosixWriteableFile only on MacOS X
mmap is proven on the other platforms, we are not changing it at the last moment before release.
This commit is contained in:
parent
648c6f4510
commit
91a94eb4ea
@ -377,6 +377,7 @@ class PosixMmapFile : public WritableFile {
|
||||
}
|
||||
};
|
||||
|
||||
#if defined(OS_MACOSX)
|
||||
class PosixWriteableFile : public WritableFile {
|
||||
private:
|
||||
std::string filename_;
|
||||
@ -461,6 +462,7 @@ class PosixWriteableFile : public WritableFile {
|
||||
return s;
|
||||
}
|
||||
};
|
||||
#endif
|
||||
|
||||
static int LockOrUnlock(int fd, bool lock) {
|
||||
errno = 0;
|
||||
@ -524,6 +526,23 @@ class PosixEnv : public Env {
|
||||
int fd = open(fname.c_str(), O_RDONLY);
|
||||
if (fd < 0) {
|
||||
s = IOError(fname, errno);
|
||||
#if !defined(OS_MACOSX)
|
||||
} else if (mmap_limit_.Acquire()) {
|
||||
uint64_t size;
|
||||
s = GetFileSize(fname, &size);
|
||||
if (s.ok()) {
|
||||
void* base = mmap(NULL, size, PROT_READ, MAP_SHARED, fd, 0);
|
||||
if (base != MAP_FAILED) {
|
||||
*result = new PosixMmapReadableFile(fname, base, size, &mmap_limit_);
|
||||
} else {
|
||||
s = IOError(fname, errno);
|
||||
}
|
||||
}
|
||||
close(fd);
|
||||
if (!s.ok()) {
|
||||
mmap_limit_.Release();
|
||||
}
|
||||
#endif
|
||||
} else {
|
||||
*result = new PosixRandomAccessFile(fname, fd);
|
||||
}
|
||||
@ -538,7 +557,11 @@ class PosixEnv : public Env {
|
||||
*result = NULL;
|
||||
s = IOError(fname, errno);
|
||||
} else {
|
||||
#if defined(OS_MACOSX)
|
||||
*result = new PosixWriteableFile(fname, fd);
|
||||
#else
|
||||
*result = new PosixMmapFile(fname, fd, page_size_);
|
||||
#endif
|
||||
}
|
||||
return s;
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user