| 644 | } |
| 645 | |
| 646 | void test_cancel(bool use_pthread) { |
| 647 | bthread::ExecutionQueueId<LongIntTask> queue_id = { 0 }; // to suppress warnings |
| 648 | bthread::ExecutionQueueOptions options; |
| 649 | options.use_pthread = use_pthread; |
| 650 | if (options.use_pthread) { |
| 651 | LOG(INFO) << "================ pthread ================"; |
| 652 | } else { |
| 653 | LOG(INFO) << "================ bthread ================"; |
| 654 | } |
| 655 | int64_t result = 0; |
| 656 | ASSERT_EQ(0, bthread::execution_queue_start(&queue_id, &options, |
| 657 | add_with_suspend2, &result)); |
| 658 | g_suspending = false; |
| 659 | bthread::TaskHandle handle0; |
| 660 | ASSERT_EQ(0, bthread::execution_queue_execute(queue_id, -100, NULL, &handle0)); |
| 661 | while (!g_suspending) { |
| 662 | usleep(10); |
| 663 | } |
| 664 | ASSERT_EQ(1, bthread::execution_queue_cancel(handle0)); |
| 665 | ASSERT_EQ(1, bthread::execution_queue_cancel(handle0)); |
| 666 | bthread::TaskHandle handle1; |
| 667 | ASSERT_EQ(0, bthread::execution_queue_execute(queue_id, 100, NULL, &handle1)); |
| 668 | ASSERT_EQ(0, bthread::execution_queue_cancel(handle1)); |
| 669 | g_suspending = false; |
| 670 | ASSERT_EQ(-1, bthread::execution_queue_cancel(handle1)); |
| 671 | ASSERT_EQ(0, bthread::execution_queue_stop(queue_id)); |
| 672 | ASSERT_EQ(0, bthread::execution_queue_join(queue_id)); |
| 673 | ASSERT_EQ(0, result); |
| 674 | } |
| 675 | |
| 676 | TEST_F(ExecutionQueueTest, cancel) { |
| 677 | for (int i = 0; i < 2; ++i) { |
no test coverage detected