diff options
author | Warren Togami <wtogami@gmail.com> | 2013-12-02 19:21:46 -1000 |
---|---|---|
committer | Wladimir J. van der Laan <laanwj@gmail.com> | 2013-12-05 13:10:24 +0100 |
commit | 77f7bcb352cfaac2549bf7f25dcaeb808204c185 (patch) | |
tree | 2f78503b04cd8c0fa4ae9f7b81c795c8270d8ebc | |
parent | 5f553f8422667f956c6a750a0febcd262f37c506 (diff) |
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.
-rw-r--r-- | src/leveldb/util/env_posix.cc | 23 |
1 files changed, 23 insertions, 0 deletions
diff --git a/src/leveldb/util/env_posix.cc b/src/leveldb/util/env_posix.cc index 9859e25c4b..aff5df9db8 100644 --- a/src/leveldb/util/env_posix.cc +++ b/src/leveldb/util/env_posix.cc @@ -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; } |