Skip to content

Commit c3d6dc7

Browse files
RONDB-757: Port slash to Mac OS X
1 parent 4bb13f1 commit c3d6dc7

File tree

3 files changed

+29
-4
lines changed

3 files changed

+29
-4
lines changed

pink/third/slash/slash/Makefile

+6-1
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,12 @@
11
CLEAN_FILES = # deliberately empty, so we can append below.
22
CXX=g++
3+
UNAME_S := $(shell uname -s)
4+
ifeq ($(UNAME_S),Darwin)
5+
LDFLAGS= -lpthread
6+
else
37
LDFLAGS= -lpthread -lrt
4-
CXXFLAGS= -g -std=c++11 -fno-builtin-memcmp -pipe -fPIC
8+
endif
9+
CXXFLAGS= -g -std=c++17 -fno-builtin-memcmp -pipe -fPIC
510
ifeq ($(shell uname -m), x86_64)
611
CXXFLAGS += -msse -msse4.2
712
endif

pink/third/slash/slash/examples/Makefile

+6-1
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,11 @@
11
CXX=g++
2+
UNAME_S := $(shell uname -s)
3+
ifeq ($(UNAME_S),Darwin)
4+
LDFLAGS= -lpthread
5+
else
26
LDFLAGS= -lpthread -lrt
3-
CXXFLAGS= -O2 -std=c++11 -fno-builtin-memcmp
7+
endif
8+
CXXFLAGS= -O2 -std=c++17 -fno-builtin-memcmp
49
ifeq ($(shell uname -m), x86_64)
510
CXXFLAGS += -msse -msse4.2
611
endif

pink/third/slash/slash/src/env.cc

+17-2
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,13 @@
1616

1717
namespace slash {
1818

19+
int port_fdatasync(int fd) {
20+
#ifdef __APPLE__
21+
return fcntl(fd, F_FULLFSYNC, 0);
22+
#else
23+
return fdatasync(fd);
24+
#endif
25+
}
1926
/*
2027
* Set the resource limits of a process
2128
*/
@@ -348,7 +355,11 @@ class PosixSequentialFile: public SequentialFile {
348355

349356
virtual Status Read(size_t n, Slice* result, char* scratch) override {
350357
Status s;
358+
#ifdef __APPLE__
359+
size_t r = fread(scratch, 1, n, file_);
360+
#else
351361
size_t r = fread_unlocked(scratch, 1, n, file_);
362+
#endif
352363

353364
*result = Slice(scratch, r);
354365

@@ -449,10 +460,12 @@ class PosixMmapFile : public WritableFile
449460

450461
bool MapNewRegion() {
451462
assert(base_ == NULL);
463+
#ifndef __APPLE__
452464
if (posix_fallocate(fd_, file_offset_, map_size_) != 0) {
453465
log_warn("ftruncate error");
454466
return false;
455467
}
468+
#endif
456469
//log_info("map_size %d fileoffset %llu", map_size_, file_offset_);
457470
void* ptr = mmap(NULL, map_size_, PROT_READ | PROT_WRITE, MAP_SHARED,
458471
fd_, file_offset_);
@@ -551,7 +564,7 @@ class PosixMmapFile : public WritableFile
551564
if (pending_sync_) {
552565
// Some unmapped data was not synced
553566
pending_sync_ = false;
554-
if (fdatasync(fd_) < 0) {
567+
if (port_fdatasync(fd_) < 0) {
555568
s = IOError(filename_, errno);
556569
}
557570
}
@@ -611,9 +624,11 @@ class MmapRWFile : public RWFile
611624
}
612625

613626
bool DoMapRegion() {
627+
#ifndef __APPLE__
614628
if (posix_fallocate(fd_, 0, map_size_) != 0) {
615629
return false;
616630
}
631+
#endif
617632
void* ptr = mmap(NULL, map_size_, PROT_READ | PROT_WRITE, MAP_SHARED, fd_, 0);
618633
if (ptr == MAP_FAILED) {
619634
return false;
@@ -718,7 +733,7 @@ class PosixRandomRWFile : public RandomRWFile {
718733
}
719734

720735
virtual Status Sync() override {
721-
if (pending_sync_ && fdatasync(fd_) < 0) {
736+
if (pending_sync_ && port_fdatasync(fd_) < 0) {
722737
return IOError(filename_, errno);
723738
}
724739
pending_sync_ = false;

0 commit comments

Comments
 (0)