@@ -377,6 +377,7 @@ class PosixMmapFile : public WritableFile {
377
377
}
378
378
};
379
379
380
+ #if defined(OS_MACOSX)
380
381
class PosixWriteableFile : public WritableFile {
381
382
private:
382
383
std::string filename_;
@@ -461,6 +462,7 @@ class PosixWriteableFile : public WritableFile {
461
462
return s;
462
463
}
463
464
};
465
+ #endif
464
466
465
467
static int LockOrUnlock (int fd, bool lock) {
466
468
errno = 0 ;
@@ -524,6 +526,23 @@ class PosixEnv : public Env {
524
526
int fd = open (fname.c_str (), O_RDONLY);
525
527
if (fd < 0 ) {
526
528
s = IOError (fname, errno);
529
+ #if !defined(OS_MACOSX)
530
+ } else if (mmap_limit_.Acquire ()) {
531
+ uint64_t size;
532
+ s = GetFileSize (fname, &size);
533
+ if (s.ok ()) {
534
+ void * base = mmap (NULL , size, PROT_READ, MAP_SHARED, fd, 0 );
535
+ if (base != MAP_FAILED) {
536
+ *result = new PosixMmapReadableFile (fname, base, size, &mmap_limit_);
537
+ } else {
538
+ s = IOError (fname, errno);
539
+ }
540
+ }
541
+ close (fd);
542
+ if (!s.ok ()) {
543
+ mmap_limit_.Release ();
544
+ }
545
+ #endif
527
546
} else {
528
547
*result = new PosixRandomAccessFile (fname, fd);
529
548
}
@@ -538,7 +557,11 @@ class PosixEnv : public Env {
538
557
*result = NULL ;
539
558
s = IOError (fname, errno);
540
559
} else {
560
+ #if defined(OS_MACOSX)
541
561
*result = new PosixWriteableFile (fname, fd);
562
+ #else
563
+ *result = new PosixMmapFile (fname, fd, page_size_);
564
+ #endif
542
565
}
543
566
return s;
544
567
}
0 commit comments