]> git.proxmox.com Git - ceph.git/blobdiff - ceph/src/rocksdb/port/win/port_win.cc
update ceph source to reef 18.1.2
[ceph.git] / ceph / src / rocksdb / port / win / port_win.cc
index bd7b55f42789ea8bd9ec05dc3bdba8460b2f8901..37e8f655ce3485398382538a0e466150f425724f 100644 (file)
 
 #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"
@@ -41,7 +42,7 @@ namespace port {
 
 #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);
 }
 
@@ -51,17 +52,18 @@ std::wstring utf8_to_utf16(const std::string& utf8) {
 }
 #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() {}
@@ -84,17 +86,16 @@ void CondVar::Wait() {
 }
 
 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);
@@ -102,7 +103,7 @@ bool CondVar::TimedWait(uint64_t abs_time_us) {
   // 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();
   }
@@ -137,13 +138,12 @@ void InitOnce(OnceType* once, void (*initializer)()) {
 
 // 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;
@@ -221,7 +221,6 @@ int truncate(const char* path, int64_t length) {
 }
 
 int Truncate(std::string path, int64_t len) {
-
   if (len < 0) {
     errno = EINVAL;
     return -1;
@@ -229,10 +228,10 @@ int Truncate(std::string path, int64_t len) {
 
   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();
@@ -277,6 +276,27 @@ void SetCpuPriority(ThreadId id, CpuPriority priority) {
   (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