From 77f7bcb352cfaac2549bf7f25dcaeb808204c185 Mon Sep 17 00:00:00 2001 From: Warren Togami Date: Mon, 2 Dec 2013 19:21:46 -1000 Subject: 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. --- src/leveldb/util/env_posix.cc | 23 +++++++++++++++++++++++ 1 file changed, 23 insertions(+) (limited to 'src/leveldb/util/env_posix.cc') 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; } -- cgit v1.2.3