Merge pull request #960 from koldat/masterFixes2

Making use of GetSystemTimePreciseAsFileTime dynamic
main
Siying Dong 9 years ago
commit 70c068c97a
  1. 12
      db/auto_roll_logger.cc
  2. 19
      port/win/env_win.cc

@ -32,8 +32,16 @@ Status AutoRollLogger::ResetLogger() {
} }
void AutoRollLogger::RollLogFile() { void AutoRollLogger::RollLogFile() {
std::string old_fname = OldInfoLogFileName( // This function is called when log is rotating. Two rotations
dbname_, env_->NowMicros(), db_absolute_path_, db_log_dir_); // can happen quickly (NowMicro returns same value). To not overwrite
// previous log file we increment by one micro second and try again.
uint64_t now = env_->NowMicros();
std::string old_fname;
do {
old_fname = OldInfoLogFileName(
dbname_, now, db_absolute_path_, db_log_dir_);
now++;
} while (env_->FileExists(old_fname).ok());
env_->RenameFile(log_fname_, old_fname); env_->RenameFile(log_fname_, old_fname);
} }

@ -1138,6 +1138,8 @@ void WinthreadCall(const char* label, std::error_code result) {
} }
} }
typedef VOID(WINAPI * FnGetSystemTimePreciseAsFileTime)(LPFILETIME);
class WinEnv : public Env { class WinEnv : public Env {
public: public:
WinEnv(); WinEnv();
@ -1676,6 +1678,7 @@ class WinEnv : public Env {
} }
virtual uint64_t NowMicros() override { virtual uint64_t NowMicros() override {
if (GetSystemTimePreciseAsFileTime_ != NULL) {
// all std::chrono clocks on windows proved to return // all std::chrono clocks on windows proved to return
// values that may repeat that is not good enough for some uses. // values that may repeat that is not good enough for some uses.
const int64_t c_UnixEpochStartTicks = 116444736000000000i64; const int64_t c_UnixEpochStartTicks = 116444736000000000i64;
@ -1685,7 +1688,7 @@ class WinEnv : public Env {
// just any microseconds because it is often used as an argument // just any microseconds because it is often used as an argument
// to TimedWait() on condition variable // to TimedWait() on condition variable
FILETIME ftSystemTime; FILETIME ftSystemTime;
GetSystemTimePreciseAsFileTime(&ftSystemTime); GetSystemTimePreciseAsFileTime_(&ftSystemTime);
LARGE_INTEGER li; LARGE_INTEGER li;
li.LowPart = ftSystemTime.dwLowDateTime; li.LowPart = ftSystemTime.dwLowDateTime;
@ -1696,6 +1699,9 @@ class WinEnv : public Env {
li.QuadPart /= c_FtToMicroSec; li.QuadPart /= c_FtToMicroSec;
return li.QuadPart; return li.QuadPart;
} }
using namespace std::chrono;
return duration_cast<microseconds>(system_clock::now().time_since_epoch()).count();
}
virtual uint64_t NowNanos() override { virtual uint64_t NowNanos() override {
// all std::chrono clocks on windows have the same resolution that is only // all std::chrono clocks on windows have the same resolution that is only
@ -2104,6 +2110,7 @@ class WinEnv : public Env {
std::vector<ThreadPool> thread_pools_; std::vector<ThreadPool> thread_pools_;
mutable std::mutex mu_; mutable std::mutex mu_;
std::vector<std::thread> threads_to_join_; std::vector<std::thread> threads_to_join_;
FnGetSystemTimePreciseAsFileTime GetSystemTimePreciseAsFileTime_;
}; };
WinEnv::WinEnv() WinEnv::WinEnv()
@ -2112,7 +2119,15 @@ WinEnv::WinEnv()
page_size_(4 * 1012), page_size_(4 * 1012),
allocation_granularity_(page_size_), allocation_granularity_(page_size_),
perf_counter_frequency_(0), perf_counter_frequency_(0),
thread_pools_(Priority::TOTAL) { thread_pools_(Priority::TOTAL),
GetSystemTimePreciseAsFileTime_(NULL) {
HMODULE module = GetModuleHandle("kernel32.dll");
if (module != NULL) {
GetSystemTimePreciseAsFileTime_ = (FnGetSystemTimePreciseAsFileTime)GetProcAddress(
module, "GetSystemTimePreciseAsFileTime");
}
SYSTEM_INFO sinfo; SYSTEM_INFO sinfo;
GetSystemInfo(&sinfo); GetSystemInfo(&sinfo);

Loading…
Cancel
Save