diff options
author | Randell Jesup <[email protected]> | 2017-03-15 18:24:07 +1300 |
---|---|---|
committer | Matthew Gregan <[email protected]> | 2017-03-15 18:24:07 +1300 |
commit | c176407b69c9784b22b8f2b5066452564b39edb9 (patch) | |
tree | 032912083bb1cb6ff41804cf09816ca582bdb33d /src/cubeb_log.cpp | |
parent | 11a7c6d4a27e7963979ed956e20b1d57ebe67ca5 (diff) | |
download | cubeb-c176407b69c9784b22b8f2b5066452564b39edb9.tar.gz cubeb-c176407b69c9784b22b8f2b5066452564b39edb9.zip |
Avoid std::thread:sleep_for since we can't use it in Gecko.
Diffstat (limited to 'src/cubeb_log.cpp')
-rw-r--r-- | src/cubeb_log.cpp | 28 |
1 files changed, 25 insertions, 3 deletions
diff --git a/src/cubeb_log.cpp b/src/cubeb_log.cpp index 0ac0836..1c5d713 100644 --- a/src/cubeb_log.cpp +++ b/src/cubeb_log.cpp @@ -9,6 +9,11 @@ #include "cubeb_log.h" #include "cubeb_ringbuffer.h" #include <cstdarg> +#ifdef _WIN32 +#include <windows.h> +#else +#include <time.h> +#endif cubeb_log_level g_log_level; cubeb_log_callback g_log_callback; @@ -19,8 +24,7 @@ const size_t CUBEB_LOG_MESSAGE_MAX_SIZE = 256; * messages. */ const size_t CUBEB_LOG_MESSAGE_QUEUE_DEPTH = 40; /** Number of milliseconds to wait before dequeuing log messages. */ -const std::chrono::milliseconds CUBEB_LOG_BATCH_PRINT_INTERVAL_MS = - std::chrono::milliseconds(10); +#define CUBEB_LOG_BATCH_PRINT_INTERVAL_MS 10 /** * This wraps an inline buffer, that represents a log message, that must be @@ -75,11 +79,29 @@ public: while (msg_queue.dequeue(&msg, 1)) { LOGV("%s", msg.get()); } - std::this_thread::sleep_for(CUBEB_LOG_BATCH_PRINT_INTERVAL_MS); +#ifdef _WIN32 + Sleep(CUBEB_LOG_BATCH_PRINT_INTERVAL_MS); +#else + timespec sleep_duration = sleep_for; + timespec remainder; + do { + if (nanosleep(&sleep_duration, &remainder) == 0 || + errno != EINTR) { + break; + } + sleep_duration = remainder; + } while (remainder.tv_sec || remainder.tv_nsec); +#endif } }).detach(); } private: +#ifndef _WIN32 + const struct timespec sleep_for = { + CUBEB_LOG_BATCH_PRINT_INTERVAL_MS/1000, + (CUBEB_LOG_BATCH_PRINT_INTERVAL_MS%1000)*1000*1000 + }; +#endif cubeb_async_logger() : msg_queue(CUBEB_LOG_MESSAGE_QUEUE_DEPTH) { |