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

Method enqueue_or_timeout

benchmarks/dlib/pipe/pipe_kernel_1.h:488–575  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

486 typename T
487 >
488 bool pipe<T>::
489 enqueue_or_timeout (
490 T& item,
491 unsigned long timeout
492 )
493 {
494 auto_mutex M(m);
495 ++enqueue_waiters;
496
497 // wait until there is room or we are disabled or
498 // we run out of time.
499 bool timed_out = false;
500 while (pipe_size == pipe_max_size && enabled && enqueue_enabled &&
501 !(pipe_max_size == 0 && dequeue_waiters > 0 && first == 1) )
502 {
503 if (timeout == 0 || enqueue_sig.wait_or_timeout(timeout) == false)
504 {
505 timed_out = true;
506 break;
507 }
508 }
509
510 if (enabled == false || timed_out || enqueue_enabled == false)
511 {
512 --enqueue_waiters;
513 // let the destructor know we are unblocking
514 unblock_sig.broadcast();
515 return false;
516 }
517
518 // set the appropriate values for first and last
519 if (pipe_size == 0)
520 {
521 first = 0;
522 last = 0;
523 }
524 else
525 {
526 last = (last+1)%pipe_max_size;
527 }
528
529
530 exchange(item,data[last]);
531
532 // wake up a call to dequeue() if there are any currently blocked
533 if (dequeue_waiters > 0)
534 dequeue_sig.signal();
535
536 if (pipe_max_size > 0)
537 {
538 ++pipe_size;
539 }
540 else
541 {
542 // wait for a dequeue to take the item out
543 while (last == 0 && enabled && enqueue_enabled)
544 enqueue_sig.wait();
545

Callers

nothing calls this directly

Calls 5

exchangeFunction · 0.85
wait_or_timeoutMethod · 0.45
broadcastMethod · 0.45
signalMethod · 0.45
waitMethod · 0.45

Tested by

no test coverage detected