MCPcopy Create free account
hub / github.com/apache/brpc / check_sleep

Function check_sleep

test/bthread_unittest.cpp:487–516  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

485}
486
487void* check_sleep(void* pthread_task) {
488 EXPECT_TRUE(bthread_self() != 0);
489 // Create a no-signal task that other worker will not steal. The task will be
490 // run if current bthread does context switch.
491 bthread_attr_t attr = BTHREAD_ATTR_NORMAL | BTHREAD_NOSIGNAL;
492 bthread_t th1;
493 pthread_t run = 0;
494 const pthread_t pid = pthread_self();
495 EXPECT_EQ(0, bthread_start_urgent(&th1, &attr, mark_run, &run));
496 if (pthread_task) {
497 bthread_usleep(100000L);
498 // due to NOSIGNAL, mark_run did not run.
499 // FIXME: actually runs. someone is still stealing.
500 // EXPECT_EQ((pthread_t)0, run);
501 // bthread_usleep = usleep for BTHREAD_ATTR_PTHREAD
502 EXPECT_EQ(pid, pthread_self());
503 // schedule mark_run
504 bthread_flush();
505 } else {
506 // start_urgent should jump to the new thread first, then back to
507 // current thread.
508 EXPECT_EQ(pid, run); // should run in the same pthread
509 }
510 EXPECT_EQ(0, bthread_join(th1, NULL));
511 if (pthread_task) {
512 EXPECT_EQ(pid, pthread_self());
513 EXPECT_NE((pthread_t)0, run); // the mark_run should run.
514 }
515 return NULL;
516}
517
518TEST_F(BthreadTest, bthread_usleep) {
519 // NOTE: May fail because worker threads may still be stealing tasks

Callers

nothing calls this directly

Calls 5

bthread_selfFunction · 0.85
bthread_start_urgentFunction · 0.85
bthread_usleepFunction · 0.85
bthread_flushFunction · 0.85
bthread_joinFunction · 0.85

Tested by

no test coverage detected