Ejemplo n.º 1
0
static void
test_cond_var()
{
    CondVar cv;
    NaCs::tic();
    for (int i = 0;i < N;i++) {
        cv.notify_one();
    }
    tocPerCycle();
    NaCs::tic();
    for (int i = 0;i < N;i++) {
        cv.notify_all();
    }
    tocPerCycle();
    std::thread thread([&] {
            Locker locker;
            for (int i = 0;i < N * 2;i++) {
                cv.wait(locker);
                std::this_thread::yield();
            }
        });
    thread.detach();
    NaCs::tic();
    for (int i = 0;i < N;i++) {
        cv.notify_one();
    }
    tocPerCycle();
    NaCs::tic();
    for (int i = 0;i < N;i++) {
        cv.notify_all();
    }
    tocPerCycle();
}
Ejemplo n.º 2
0
 void synchronized_await(Mutex& mtx, CondVar& cv) {
     CPPA_REQUIRE(!closed());
     if (try_block()) {
         std::unique_lock<Mutex> guard(mtx);
         while (blocked()) cv.wait(guard);
     }
 }
Ejemplo n.º 3
0
void condvar_wait(Guard& guard, CondVar& condvar, 
          bool has_timeout, boost::system_time timeout_time = boost::system_time()) {
  if (has_timeout) {
    condvar.timed_wait(guard, timeout_time);
  } else {
    condvar.wait(guard);
  }
}
 void synchronized_await(Mutex& mtx, CondVar& cv) {
   CAF_ASSERT(! closed());
   if (! can_fetch_more() && try_block()) {
     std::unique_lock<Mutex> guard(mtx);
     while (blocked()) {
       cv.wait(guard);
     }
   }
 }
Ejemplo n.º 5
0
  size_t pri_synchronized_reset(Mutex& mtx, CondVar& cv)
  {
    ACTX_ASSERTS(!blocked());
    auto c = reset();
    if (c != 0)
    {
      return c;
    }

    std::unique_lock<Mutex> guard{mtx};
    block();
    auto _ = gsl::finally([this]() {unblock(); });
    c = reset();
    while (c == 0)
    {
      cv.wait(guard);
      c = reset();
    }

    return c;
  }