#include "port/win/port_win.h"
+#include <assert.h>
#include <io.h>
-#include "port/port_dirent.h"
-#include "port/sys_time.h"
-
-#include <cstdlib>
+#include <rpc.h>
#include <stdio.h>
-#include <assert.h>
#include <string.h>
-#include <memory>
-#include <exception>
#include <chrono>
+#include <cstdlib>
+#include <exception>
+#include <memory>
+
+#include "port/port_dirent.h"
+#include "port/sys_time.h"
#ifdef ROCKSDB_WINDOWS_UTF8_FILENAMES
// utf8 <-> utf16
-#include <string>
-#include <locale>
#include <codecvt>
+#include <locale>
+#include <string>
#endif
#include "logging/logging.h"
#ifdef ROCKSDB_WINDOWS_UTF8_FILENAMES
std::string utf16_to_utf8(const std::wstring& utf16) {
- std::wstring_convert<std::codecvt_utf8_utf16<wchar_t>,wchar_t> convert;
+ std::wstring_convert<std::codecvt_utf8_utf16<wchar_t>, wchar_t> convert;
return convert.to_bytes(utf16);
}
}
#endif
-void gettimeofday(struct timeval* tv, struct timezone* /* tz */) {
- using namespace std::chrono;
-
- microseconds usNow(
- duration_cast<microseconds>(system_clock::now().time_since_epoch()));
+void GetTimeOfDay(TimeVal* tv, struct timezone* /* tz */) {
+ std::chrono::microseconds usNow(
+ std::chrono::duration_cast<std::chrono::microseconds>(
+ std::chrono::system_clock::now().time_since_epoch()));
- seconds secNow(duration_cast<seconds>(usNow));
+ std::chrono::seconds secNow(
+ std::chrono::duration_cast<std::chrono::seconds>(usNow));
tv->tv_sec = static_cast<long>(secNow.count());
- tv->tv_usec = static_cast<long>(usNow.count() -
- duration_cast<microseconds>(secNow).count());
+ tv->tv_usec = static_cast<long>(
+ usNow.count() -
+ std::chrono::duration_cast<std::chrono::microseconds>(secNow).count());
}
Mutex::~Mutex() {}
}
bool CondVar::TimedWait(uint64_t abs_time_us) {
-
- using namespace std::chrono;
-
// MSVC++ library implements wait_until in terms of wait_for so
// we need to convert absolute wait into relative wait.
- microseconds usAbsTime(abs_time_us);
+ std::chrono::microseconds usAbsTime(abs_time_us);
- microseconds usNow(
- duration_cast<microseconds>(system_clock::now().time_since_epoch()));
- microseconds relTimeUs =
- (usAbsTime > usNow) ? (usAbsTime - usNow) : microseconds::zero();
+ std::chrono::microseconds usNow(
+ std::chrono::duration_cast<std::chrono::microseconds>(
+ std::chrono::system_clock::now().time_since_epoch()));
+ std::chrono::microseconds relTimeUs = (usAbsTime > usNow)
+ ? (usAbsTime - usNow)
+ : std::chrono::microseconds::zero();
// Caller must ensure that mutex is held prior to calling this method
std::unique_lock<std::mutex> lk(mu_->getLock(), std::adopt_lock);
// Work around https://github.com/microsoft/STL/issues/369
#if defined(_MSC_VER) && \
(!defined(_MSVC_STL_UPDATE) || _MSVC_STL_UPDATE < 202008L)
- if (relTimeUs == microseconds::zero()) {
+ if (relTimeUs == std::chrono::microseconds::zero()) {
lk.unlock();
lk.lock();
}
// Private structure, exposed only by pointer
struct DIR {
- HANDLE handle_;
- bool firstread_;
+ HANDLE handle_;
+ bool firstread_;
RX_WIN32_FIND_DATA data_;
dirent entry_;
- DIR() : handle_(INVALID_HANDLE_VALUE),
- firstread_(true) {}
+ DIR() : handle_(INVALID_HANDLE_VALUE), firstread_(true) {}
DIR(const DIR&) = delete;
DIR& operator=(const DIR&) = delete;
}
int Truncate(std::string path, int64_t len) {
-
if (len < 0) {
errno = EINVAL;
return -1;
HANDLE hFile =
RX_CreateFile(RX_FN(path).c_str(), GENERIC_READ | GENERIC_WRITE,
- FILE_SHARE_READ | FILE_SHARE_WRITE | FILE_SHARE_DELETE,
- NULL, // Security attrs
- OPEN_EXISTING, // Truncate existing file only
- FILE_ATTRIBUTE_NORMAL, NULL);
+ FILE_SHARE_READ | FILE_SHARE_WRITE | FILE_SHARE_DELETE,
+ NULL, // Security attrs
+ OPEN_EXISTING, // Truncate existing file only
+ FILE_ATTRIBUTE_NORMAL, NULL);
if (INVALID_HANDLE_VALUE == hFile) {
auto lastError = GetLastError();
(void)priority;
}
+int64_t GetProcessID() { return GetCurrentProcessId(); }
+
+bool GenerateRfcUuid(std::string* output) {
+ UUID uuid;
+ UuidCreateSequential(&uuid);
+
+ RPC_CSTR rpc_str;
+ auto status = UuidToStringA(&uuid, &rpc_str);
+ if (status != RPC_S_OK) {
+ return false;
+ }
+
+ // rpc_str is nul-terminated
+ *output = reinterpret_cast<char*>(rpc_str);
+
+ status = RpcStringFreeA(&rpc_str);
+ assert(status == RPC_S_OK);
+
+ return true;
+}
+
} // namespace port
} // namespace ROCKSDB_NAMESPACE