#include "third_party/fmt/core.h"
+#include <thread>
+
#ifdef HAVE_UNISTD_H
# include <unistd.h>
#endif
#include <sstream>
#include <thread>
-// AIX/PASE does not properly define usleep within its headers. However, the
-// function is available in libc.a.
-#ifdef _AIX
-extern "C" int usleep(useconds_t);
-#endif
-
namespace {
#ifndef _WIN32
LOG("lockfile_acquire: failed to acquire {}; sleeping {} microseconds",
lockfile,
to_sleep);
- usleep(to_sleep);
+ std::this_thread::sleep_for(std::chrono::microseconds(to_sleep));
slept += to_sleep;
to_sleep = std::min(max_to_sleep, 2 * to_sleep);
} else if (content != initial_content) {
HANDLE
do_acquire_win32(const std::string& lockfile, uint32_t staleness_limit)
{
- unsigned to_sleep = 1000; // Microseconds.
- unsigned max_to_sleep = 10000; // Microseconds.
- unsigned slept = 0; // Microseconds.
+ const uint32_t max_to_sleep = 10000; // Microseconds.
+ uint32_t to_sleep = 1000; // Microseconds.
+ uint32_t slept = 0; // Microseconds.
HANDLE handle;
while (true) {
LOG("lockfile_acquire: failed to acquire {}; sleeping {} microseconds",
lockfile,
to_sleep);
- usleep(to_sleep);
+ std::this_thread::sleep_for(std::chrono::microseconds(to_sleep));
slept += to_sleep;
to_sleep = std::min(max_to_sleep, 2 * to_sleep);
}
-// Copyright (C) 2020 Joel Rosdahl and other contributors
+// Copyright (C) 2020-2021 Joel Rosdahl and other contributors
//
// See doc/AUTHORS.adoc for a complete list of contributors.
//
}
#endif
-void
-usleep(int64_t usec)
-{
- std::this_thread::sleep_for(std::chrono::microseconds(usec));
-}
-
struct tm*
localtime_r(time_t* _clock, struct tm* _result)
{