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.

33 lines
1.1 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. diff --git a/src/thread_base.cc b/src/thread_base.cc
  11. index 081791d4..275015ab 100644
  12. --- a/src/thread_base.cc
  13. +++ b/src/thread_base.cc
  14. @@ -42,6 +42,8 @@
  15. #include <cstdlib>
  16. #include <cstring>
  17. #include <iostream>
  18. +#include <chrono>
  19. +#include <thread>
  20. #include <signal.h>
  21. #include <unistd.h>
  22. #include <rak/error_number.h>
  23. @@ -66,7 +68,7 @@ class lt_cacheline_aligned thread_queue_hack {
  24. thread_queue_hack() { std::memset(this, 0, sizeof(thread_queue_hack)); }
  25. - void lock() { while (!__sync_bool_compare_and_swap(&m_lock, 0, 1)) usleep(0); }
  26. + void lock() { while (!__sync_bool_compare_and_swap(&m_lock, 0, 1)) std::this_thread::sleep_for(std::chrono::microseconds(0)); }
  27. void unlock() { __sync_bool_compare_and_swap(&m_lock, 1, 0); }
  28. iterator begin() { return m_queue; }