15#ifndef THREAD_BOOST_PRIMITIVES_H_ 
   16#define THREAD_BOOST_PRIMITIVES_H_ 
   18#include <absl/base/thread_annotations.h> 
   19#include <absl/log/log.h> 
   20#include <absl/status/status.h> 
   21#include <absl/time/clock.h> 
   22#include <boost/fiber/condition_variable.hpp> 
   23#include <boost/fiber/mutex.hpp> 
   25namespace act::concurrency::impl {
 
   26class ABSL_LOCKABLE ABSL_ATTRIBUTE_WARN_UNUSED Mutex {
 
   31  void Lock() noexcept ABSL_EXCLUSIVE_LOCK_FUNCTION();
 
   32  void Unlock() noexcept ABSL_UNLOCK_FUNCTION();
 
   34  void lock() noexcept ABSL_EXCLUSIVE_LOCK_FUNCTION() { Lock(); }
 
   36  void unlock() noexcept ABSL_UNLOCK_FUNCTION() { Unlock(); }
 
   41  boost::fibers::mutex& GetImpl();
 
   42  boost::fibers::mutex mu_;
 
   45class ABSL_SCOPED_LOCKABLE MutexLock {
 
   47  explicit MutexLock(Mutex* absl_nonnull mu) ABSL_EXCLUSIVE_LOCK_FUNCTION
 
   54  MutexLock(
const MutexLock&) = 
delete;  
 
   55  MutexLock(MutexLock&&) = 
delete;       
 
   56  MutexLock& operator=(
const MutexLock&) = 
delete;
 
   57  MutexLock& operator=(MutexLock&&) = 
delete;
 
   59  ~MutexLock() ABSL_UNLOCK_FUNCTION() { mu_->Unlock(); }
 
   62  Mutex* absl_nonnull 
const mu_;
 
   69  CondVar(
const CondVar&) = 
delete;
 
   70  CondVar& operator=(
const CondVar&) = 
delete;
 
   72  void Wait(Mutex* absl_nonnull mu) 
noexcept ABSL_SHARED_LOCKS_REQUIRED(mu);
 
   74  bool WaitWithTimeout(Mutex* absl_nonnull mu, absl::Duration timeout) 
noexcept 
   76      ABSL_SHARED_LOCKS_REQUIRED(mu) {
 
   77    return WaitWithDeadline(mu, absl::Now() + timeout);
 
   80  bool WaitWithDeadline(Mutex* absl_nonnull mu,
 
   81                        const absl::Time& deadline) 
noexcept 
   82      ABSL_SHARED_LOCKS_REQUIRED(mu);
 
   84  void Signal() noexcept {
 
   87    } 
catch (boost::fibers::lock_error& error) {
 
   88      LOG(FATAL) << 
"Error in underlying implementation: " << error.what();
 
   93  void SignalAll() noexcept {
 
   96    } 
catch (boost::fibers::lock_error& error) {
 
   97      LOG(FATAL) << 
"Error in underlying implementation: " << error.what();
 
  103  boost::fibers::condition_variable_any cv_;
 
  106inline void SleepFor(absl::Duration duration) {
 
  107  boost::fibers::context* active_ctx = boost::fibers::context::active();
 
  108  active_ctx->wait_until(std::chrono::steady_clock::now() +
 
  109                         absl::ToChronoNanoseconds(duration));