You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

31 lines
1.0 KiB

  1. From b3d75a642177f21f00d18f0e46bca4a9f363d08e Mon Sep 17 00:00:00 2001
  2. From: Rosen Penev <rosenp@gmail.com>
  3. Date: Fri, 23 Aug 2019 13:35:28 -0700
  4. Subject: [PATCH] Replace usleep with C++11 sleep_for
  5. usleep was deprecated with POSIX 2008 and optionally unavailable with
  6. uClibc-ng.
  7. ---
  8. src/thread_base.cc | 4 +++-
  9. 1 file changed, 3 insertions(+), 1 deletion(-)
  10. --- a/src/thread_base.cc
  11. +++ b/src/thread_base.cc
  12. @@ -42,6 +42,8 @@
  13. #include <cstdlib>
  14. #include <cstring>
  15. #include <iostream>
  16. +#include <chrono>
  17. +#include <thread>
  18. #include <signal.h>
  19. #include <unistd.h>
  20. #include <rak/error_number.h>
  21. @@ -66,7 +68,7 @@ public:
  22. thread_queue_hack() { std::memset(this, 0, sizeof(thread_queue_hack)); }
  23. - void lock() { while (!__sync_bool_compare_and_swap(&m_lock, 0, 1)) usleep(0); }
  24. + void lock() { while (!__sync_bool_compare_and_swap(&m_lock, 0, 1)) std::this_thread::sleep_for(std::chrono::microseconds(0)); }
  25. void unlock() { __sync_bool_compare_and_swap(&m_lock, 1, 0); }
  26. iterator begin() { return m_queue; }