MCPcopy Create free account
hub / github.com/cameron314/concurrentqueue / dequeue_or_timeout

Method dequeue_or_timeout

benchmarks/dlib/pipe/pipe_kernel_1.h:582–644  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

580 typename T
581 >
582 bool pipe<T>::
583 dequeue_or_timeout (
584 T& item,
585 unsigned long timeout
586 )
587 {
588 auto_mutex M(m);
589 ++dequeue_waiters;
590
591 if (pipe_size == 0)
592 {
593 // notify wait_for_num_blocked_dequeues()
594 if (unblock_sig_waiters > 0)
595 unblock_sig.broadcast();
596
597 // notify any blocked enqueue_or_timeout() calls
598 if (enqueue_waiters > 0)
599 enqueue_sig.broadcast();
600 }
601
602 bool timed_out = false;
603 // wait until there is something in the pipe or we are disabled or we timeout.
604 while (pipe_size == 0 && enabled && dequeue_enabled &&
605 !(pipe_max_size == 0 && first == 0 && last == 0) )
606 {
607 if (timeout == 0 || dequeue_sig.wait_or_timeout(timeout) == false)
608 {
609 timed_out = true;
610 break;
611 }
612 }
613
614 if (enabled == false || timed_out || dequeue_enabled == false)
615 {
616 --dequeue_waiters;
617 // let the destructor know we are unblocking
618 unblock_sig.broadcast();
619 return false;
620 }
621
622 exchange(item,data[first]);
623
624 if (pipe_max_size > 0)
625 {
626 // set the appropriate values for first
627 first = (first+1)%pipe_max_size;
628
629 --pipe_size;
630 }
631 else
632 {
633 // let the enqueue waiting on us know that we took the
634 // item out already.
635 last = 1;
636 }
637
638 // wake up a call to enqueue() if there are any currently blocked
639 if (enqueue_waiters > 0)

Callers

nothing calls this directly

Calls 3

exchangeFunction · 0.85
broadcastMethod · 0.45
wait_or_timeoutMethod · 0.45

Tested by

no test coverage detected