Skip to content

Commit

Permalink
Align EnvPosix and EnvWindows.
Browse files Browse the repository at this point in the history
Fixes #695.

PiperOrigin-RevId: 252895299
  • Loading branch information
pwnall authored and cmumford committed Jun 13, 2019
1 parent 69061b4 commit e0d5f83
Show file tree
Hide file tree
Showing 2 changed files with 316 additions and 227 deletions.
20 changes: 10 additions & 10 deletions util/env_posix.cc
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,7 @@ int g_open_read_only_file_limit = -1;
// Up to 1000 mmap regions for 64-bit binaries; none for 32-bit.
constexpr const int kDefaultMmapLimit = (sizeof(void*) >= 8) ? 1000 : 0;

// Can be set using EnvPosixTestHelper::SetReadOnlyMMapLimit.
// Can be set using EnvPosixTestHelper::SetReadOnlyMMapLimit().
int g_mmap_limit = kDefaultMmapLimit;

// Common flags defined for all posix open operations
Expand Down Expand Up @@ -491,7 +491,8 @@ class PosixEnv : public Env {
public:
PosixEnv();
~PosixEnv() override {
static char msg[] = "PosixEnv singleton destroyed. Unsupported behavior!\n";
static const char msg[] =
"PosixEnv singleton destroyed. Unsupported behavior!\n";
std::fwrite(msg, 1, sizeof(msg), stderr);
std::abort();
}
Expand Down Expand Up @@ -663,7 +664,10 @@ class PosixEnv : public Env {
void* background_work_arg) override;

void StartThread(void (*thread_main)(void* thread_main_arg),
void* thread_main_arg) override;
void* thread_main_arg) override {
std::thread new_thread(thread_main, thread_main_arg);
new_thread.detach();
}

Status GetTestDirectory(std::string* result) override {
const char* env = std::getenv("TEST_TMPDIR");
Expand Down Expand Up @@ -708,7 +712,9 @@ class PosixEnv : public Env {
return static_cast<uint64_t>(tv.tv_sec) * kUsecondsPerSecond + tv.tv_usec;
}

void SleepForMicroseconds(int micros) override { ::usleep(micros); }
void SleepForMicroseconds(int micros) override {
std::this_thread::sleep_for(std::chrono::microseconds(micros));

This comment has been minimized.

Copy link
@tmm1

tmm1 Jul 20, 2019

FYI, gcc 4.7 has basic support for c++11 but it doesn't include sleep_for. I had to revert this change to build with that ancient compiler (which I need for some embedded ARM systems where I'm using leveldb).

}

private:
void BackgroundThreadMain();
Expand Down Expand Up @@ -869,12 +875,6 @@ using PosixDefaultEnv = SingletonEnv<PosixEnv>;

} // namespace

void PosixEnv::StartThread(void (*thread_main)(void* thread_main_arg),
void* thread_main_arg) {
std::thread new_thread(thread_main, thread_main_arg);
new_thread.detach();
}

void EnvPosixTestHelper::SetReadOnlyFDLimit(int limit) {
PosixDefaultEnv::AssertEnvNotInitialized();
g_open_read_only_file_limit = limit;
Expand Down
Loading

0 comments on commit e0d5f83

Please sign in to comment.