| 314 | } |
| 315 | |
| 316 | void test_execute_urgent(bool use_pthread) { |
| 317 | g_should_be_urgent = false; |
| 318 | pthread_t threads[10]; |
| 319 | bthread::ExecutionQueueId<LongIntTask> queue_id = { 0 }; // to suppress warnings |
| 320 | bthread::ExecutionQueueOptions options; |
| 321 | options.use_pthread = use_pthread; |
| 322 | if (options.use_pthread) { |
| 323 | LOG(INFO) << "================ pthread ================"; |
| 324 | } else { |
| 325 | LOG(INFO) << "================ bthread ================"; |
| 326 | } |
| 327 | int64_t result = 0; |
| 328 | ASSERT_EQ(0, bthread::execution_queue_start(&queue_id, &options, |
| 329 | add_with_suspend, &result)); |
| 330 | PushArg pa; |
| 331 | pa.id = queue_id; |
| 332 | pa.total_num = 0; |
| 333 | pa.total_time = 0; |
| 334 | pa.expected_value = 0; |
| 335 | pa.stopped = false; |
| 336 | pa.wait_task_completed = true; |
| 337 | for (size_t i = 0; i < ARRAY_SIZE(threads); ++i) { |
| 338 | pthread_create(&threads[i], NULL, &push_thread, &pa); |
| 339 | } |
| 340 | g_suspending = false; |
| 341 | usleep(1000); |
| 342 | |
| 343 | for (int i = 0; i < 100; ++i) { |
| 344 | ASSERT_EQ(0, bthread::execution_queue_execute(queue_id, -100)); |
| 345 | while (!g_suspending) { |
| 346 | usleep(100); |
| 347 | } |
| 348 | ASSERT_EQ(0, bthread::execution_queue_execute( |
| 349 | queue_id, -1, &bthread::TASK_OPTIONS_URGENT)); |
| 350 | g_suspending = false; |
| 351 | usleep(100); |
| 352 | } |
| 353 | usleep(500* 1000); |
| 354 | pa.stopped = true; |
| 355 | ASSERT_EQ(0, bthread::execution_queue_stop(queue_id)); |
| 356 | for (size_t i = 0; i < ARRAY_SIZE(threads); ++i) { |
| 357 | pthread_join(threads[i], NULL); |
| 358 | } |
| 359 | LOG(INFO) << "result=" << result; |
| 360 | ASSERT_EQ(0, bthread::execution_queue_join(queue_id)); |
| 361 | ASSERT_EQ(pa.expected_value.load(), result); |
| 362 | } |
| 363 | |
| 364 | TEST_F(ExecutionQueueTest, execute_urgent) { |
| 365 | for (int i = 0; i < 2; ++i) { |
no test coverage detected