Skip to content

Commit

Permalink
Replace usleep with C++11 sleep_for
Browse files Browse the repository at this point in the history
usleep was deprecated with POSIX 2008 and optionally unavailable with
uClibc-ng.
  • Loading branch information
neheb committed Aug 28, 2019
1 parent 7659cd0 commit 732ab8f
Showing 1 changed file with 3 additions and 1 deletion.
4 changes: 3 additions & 1 deletion src/thread_base.cc
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,8 @@
#include <cstdlib>
#include <cstring>
#include <iostream>
#include <chrono>
#include <thread>
#include <signal.h>
#include <unistd.h>
#include <rak/error_number.h>
Expand All @@ -66,7 +68,7 @@ class lt_cacheline_aligned thread_queue_hack {

thread_queue_hack() { std::memset(this, 0, sizeof(thread_queue_hack)); }

void lock() { while (!__sync_bool_compare_and_swap(&m_lock, 0, 1)) usleep(0); }
void lock() { while (!__sync_bool_compare_and_swap(&m_lock, 0, 1)) std::this_thread::sleep_for(std::chrono::microseconds(0); }
void unlock() { __sync_bool_compare_and_swap(&m_lock, 1, 0); }

iterator begin() { return m_queue; }
Expand Down

0 comments on commit 732ab8f

Please sign in to comment.