MCPcopy Create free account
hub / github.com/cameron314/readerwriterqueue / blocking

Method blocking

tests/unittests/unittests.cpp:504–607  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

502 }
503
504 bool blocking()
505 {
506 {
507 BlockingReaderWriterQueue<int> q;
508 int item;
509
510 q.enqueue(123);
511 ASSERT_OR_FAIL(q.try_dequeue(item));
512 ASSERT_OR_FAIL(item == 123);
513 ASSERT_OR_FAIL(q.size_approx() == 0);
514
515 q.enqueue(234);
516 ASSERT_OR_FAIL(q.size_approx() == 1);
517 ASSERT_OR_FAIL(*q.peek() == 234);
518 ASSERT_OR_FAIL(*q.peek() == 234);
519 ASSERT_OR_FAIL(q.pop());
520
521 ASSERT_OR_FAIL(q.try_enqueue(345));
522 q.wait_dequeue(item);
523 ASSERT_OR_FAIL(item == 345);
524 ASSERT_OR_FAIL(!q.peek());
525 ASSERT_OR_FAIL(q.size_approx() == 0);
526 ASSERT_OR_FAIL(!q.try_dequeue(item));
527 }
528
529 weak_atomic<int> result;
530 result = 1;
531
532 {
533 BlockingReaderWriterQueue<int> q(100);
534 SimpleThread reader([&]() {
535 int item = -1;
536 int prevItem = -1;
537 for (int i = 0; i != 1000000; ++i) {
538 q.wait_dequeue(item);
539 if (item <= prevItem) {
540 result = 0;
541 }
542 prevItem = item;
543 }
544 });
545 SimpleThread writer([&]() {
546 for (int i = 0; i != 1000000; ++i) {
547 q.enqueue(i);
548 }
549 });
550
551 writer.join();
552 reader.join();
553
554 ASSERT_OR_FAIL(q.size_approx() == 0);
555 ASSERT_OR_FAIL(result.load());
556 }
557
558 {
559 BlockingReaderWriterQueue<int> q(100);
560 SimpleThread reader([&]() {
561 int item = -1;

Callers

nothing calls this directly

Calls 12

popMethod · 0.80
joinMethod · 0.80
loadMethod · 0.80
emplaceMethod · 0.80
get_valueMethod · 0.80
enqueueMethod · 0.45
try_dequeueMethod · 0.45
size_approxMethod · 0.45
peekMethod · 0.45
try_enqueueMethod · 0.45
wait_dequeueMethod · 0.45
wait_dequeue_timedMethod · 0.45

Tested by

no test coverage detected