| 648 | } |
| 649 | |
| 650 | bool enqueue_bulk() |
| 651 | { |
| 652 | typedef TestTraits<2> Traits2; |
| 653 | typedef TestTraits<4> Traits4; |
| 654 | |
| 655 | int arr123[] = { 1, 2, 3 }; |
| 656 | int arr1234[] = { 1, 2, 3, 4 }; |
| 657 | int arr123456[] = { 1, 2, 3, 4, 5, 6 }; |
| 658 | |
| 659 | Traits2::reset(); |
| 660 | { |
| 661 | // Implicit, block allocation required |
| 662 | ConcurrentQueue<int, Traits2> q(2); |
| 663 | ASSERT_OR_FAIL(Traits2::malloc_count() == 1); |
| 664 | |
| 665 | q.enqueue_bulk(arr123, 3); |
| 666 | ASSERT_OR_FAIL(Traits2::malloc_count() == 4); // One for producer, one for block index, one for block |
| 667 | |
| 668 | int item; |
| 669 | for (int i = 0; i != 3; ++i) { |
| 670 | ASSERT_OR_FAIL(q.try_dequeue(item)); |
| 671 | ASSERT_OR_FAIL(item == i + 1); |
| 672 | } |
| 673 | ASSERT_OR_FAIL(!q.try_dequeue(item)); |
| 674 | } |
| 675 | |
| 676 | Traits4::reset(); |
| 677 | { |
| 678 | // Implicit, block allocation not required (end on block boundary) |
| 679 | ConcurrentQueue<int, Traits4> q(2); |
| 680 | ASSERT_OR_FAIL(Traits4::malloc_count() == 1); |
| 681 | |
| 682 | q.enqueue_bulk(arr1234, 4); |
| 683 | ASSERT_OR_FAIL(Traits4::malloc_count() == 3); // One for producer, one for block index |
| 684 | |
| 685 | int item; |
| 686 | for (int i = 0; i != 4; ++i) { |
| 687 | ASSERT_OR_FAIL(q.try_dequeue(item)); |
| 688 | ASSERT_OR_FAIL(item == i + 1); |
| 689 | } |
| 690 | ASSERT_OR_FAIL(!q.try_dequeue(item)); |
| 691 | } |
| 692 | |
| 693 | Traits2::reset(); |
| 694 | { |
| 695 | // Implicit, allocation fail |
| 696 | ConcurrentQueue<int, Traits2> q(2); |
| 697 | ASSERT_OR_FAIL(Traits2::malloc_count() == 1); |
| 698 | |
| 699 | ASSERT_OR_FAIL(!q.try_enqueue_bulk(arr123, 3)); |
| 700 | ASSERT_OR_FAIL(Traits2::malloc_count() == 3); // Still has to allocate implicit producer and block index |
| 701 | |
| 702 | int item; |
| 703 | ASSERT_OR_FAIL(!q.try_dequeue(item)); |
| 704 | |
| 705 | ASSERT_OR_FAIL(q.try_enqueue_bulk(arr123, 2)); |
| 706 | for (int i = 0; i != 2; ++i) { |
| 707 | ASSERT_OR_FAIL(q.try_dequeue(item)); |
no test coverage detected