/* Copyright (c) 2003-2004, Roger Dingledine
* Copyright (c) 2004-2006, Roger Dingledine, Nick Mathewson.
- * Copyright (c) 2007-2021, The Tor Project, Inc. */
+ * Copyright (c) 2007-2025, The Tor Project, Inc. */
/* See LICENSE for licensing information */
/**
#undef HAVE_CLOCK_GETTIME
#endif
-#ifdef TOR_UNIT_TESTS
-/** Delay for <b>msec</b> milliseconds. Only used in tests. */
+/** Delay for <b>msec</b> milliseconds. */
void
tor_sleep_msec(int msec)
{
#ifdef _WIN32
Sleep(msec);
+#elif defined(HAVE_TIME_H)
+ struct timespec ts = {msec / 1000, (msec % 1000) * 1000 * 1000};
+ while (nanosleep(&ts, &ts) == -1 && errno == EINTR);
#elif defined(HAVE_USLEEP)
sleep(msec / 1000);
/* Some usleep()s hate sleeping more than 1 sec */
sleep(CEIL_DIV(msec, 1000));
#endif /* defined(_WIN32) || ... */
}
-#endif /* defined(TOR_UNIT_TESTS) */
#define ONE_MILLION ((int64_t) (1000 * 1000))
#define ONE_BILLION ((int64_t) (1000 * 1000 * 1000))
/* Copyright (c) 2003-2004, Roger Dingledine
* Copyright (c) 2004-2006, Roger Dingledine, Nick Mathewson.
- * Copyright (c) 2007-2021, The Tor Project, Inc. */
+ * Copyright (c) 2007-2025, The Tor Project, Inc. */
/* See LICENSE for licensing information */
/**
#endif /* SIZEOF_VOID_P == 8 */
}
-#ifdef TOR_UNIT_TESTS
void tor_sleep_msec(int msec);
+#ifdef TOR_UNIT_TESTS
void monotime_enable_test_mocking(void);
void monotime_disable_test_mocking(void);
void monotime_set_mock_time_nsec(int64_t);