示例#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();
}
示例#2
0
 void synchronized_incr(Mutex& mtx, CondVar& cv)
 {
   incr(
     [&](self_t& seq)
     {
       std::unique_lock<Mutex> guard{mtx};
       cv.notify_one();
     });
 }
示例#3
0
 bool synchronized_push_front(Mutex& mtx, CondVar& cv, pointer ptr) {
   switch (push_front(ptr)) {
     default:
       // enqueued message to a running actor's mailbox
       return true;
     case inbox_result::unblocked_reader: {
       std::unique_lock<Mutex> guard(mtx);
       cv.notify_one();
       return true;
     }
     case inbox_result::queue_closed:
       // actor no longer alive
       return false;
   }
 }
示例#4
0
 bool synchronized_enqueue(Mutex& mtx, CondVar& cv, pointer new_element) {
     switch (enqueue(new_element)) {
         case enqueue_result::unblocked_reader: {
             std::unique_lock<Mutex> guard(mtx);
             cv.notify_one();
             return true;
         }
         case enqueue_result::success:
             // enqueued message to a running actor's mailbox
             return true;
         case enqueue_result::queue_closed:
             // actor no longer alive
             return false;
     }
     // should be unreachable
     CPPA_CRITICAL("invalid result of enqueue()");
 }