#include <condition_variable>
#include <fcntl.h>
#include <mutex>
-#include <pthread.h>
namespace folly {
std::chrono::microseconds busy;
std::chrono::microseconds idle;
- loopThread_.store(pthread_self(), std::memory_order_release);
+ loopThread_.store(std::this_thread::get_id(), std::memory_order_release);
if (!name_.empty()) {
setThreadName(name_);
* check if the event base loop is running.
*/
bool isRunning() const {
- return loopThread_.load(std::memory_order_relaxed) != 0;
+ return loopThread_.load(std::memory_order_relaxed) != std::thread::id();
}
/**
*/
bool isInEventBaseThread() const {
auto tid = loopThread_.load(std::memory_order_relaxed);
- return tid == 0 || pthread_equal(tid, pthread_self());
+ return tid == std::thread::id() || tid == std::this_thread::get_id();
}
bool inRunningEventBaseThread() const {
- return pthread_equal(
- loopThread_.load(std::memory_order_relaxed), pthread_self());
+ return loopThread_.load(std::memory_order_relaxed) ==
+ std::this_thread::get_id();
}
HHWheelTimer& timer() {
std::atomic<bool> stop_;
// The ID of the thread running the main loop.
- // 0 if loop is not running.
- // Note: POSIX doesn't guarantee that 0 is an invalid pthread_t (or
- // even that atomic<pthread_t> is valid), but that's how it is
- // everywhere (at least on Linux, FreeBSD, and OSX).
- std::atomic<pthread_t> loopThread_;
+ // std::thread::id{} if loop is not running.
+ std::atomic<std::thread::id> loopThread_;
// pointer to underlying event_base class doing the heavy lifting
event_base* evb_;