当前位置: 首页>>代码示例>>C++>>正文


C++ Baton类代码示例

本文整理汇总了C++中Baton的典型用法代码示例。如果您正苦于以下问题:C++ Baton类的具体用法?C++ Baton怎么用?C++ Baton使用的例子?那么, 这里精选的类代码示例或许可以为您提供帮助。


在下文中一共展示了Baton类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。

示例1: run_timed_wait_regular_test

void run_timed_wait_regular_test() {
  Baton<Atom> b;

  auto thr = DSched::thread([&] {
    // To wait forever we'd like to use time_point<Clock>::max, but
    // std::condition_variable does math to convert the timeout to
    // system_clock without handling overflow.
    auto farFuture = Clock::now() + std::chrono::hours(1000);
    bool rv = b.timed_wait(farFuture);
    if (!std::is_same<Atom<int>, DeterministicAtomic<int>>::value) {
      // DeterministicAtomic ignores actual times, so doesn't guarantee
      // a lack of timeout
      EXPECT_TRUE(rv);
    }
  });

  if (!std::is_same<Atom<int>, DeterministicAtomic<int>>::value) {
    // If we are using std::atomic (or EmulatedFutexAtomic) then
    // a sleep here guarantees to a large extent that 'thr' will
    // execute wait before we post it, thus testing late delivery. For
    // DeterministicAtomic, we just rely on DeterministicSchedule to do
    // the scheduling.  The test won't fail if we lose the race, we just
    // don't get coverage.
    std::this_thread::sleep_for(std::chrono::milliseconds(2));
  }

  b.post();
  DSched::join(thr);
}
开发者ID:AddictXQ,项目名称:folly,代码行数:29,代码来源:BatonTest.cpp

示例2: TEST_F

TEST_F(EventBaseThreadTest, example) {
  EventBaseThread ebt;

  Baton<> done;
  ebt.getEventBase()->runInEventBaseThread([&] { done.post(); });
  ASSERT_TRUE(done.timed_wait(seconds(1)));
}
开发者ID:charsyam,项目名称:folly,代码行数:7,代码来源:EventBaseThreadTest.cpp

示例3: TEST

TEST(Interrupt, withinTimedOut) {
  Promise<int> p;
  Baton<> done;
  p.setInterruptHandler([&](const exception_wrapper& /* e */) { done.post(); });
  p.getFuture().within(std::chrono::milliseconds(1));
  // Give it 100ms to time out and call the interrupt handler
  auto t = std::chrono::steady_clock::now() + std::chrono::milliseconds(100);
  EXPECT_TRUE(done.timed_wait(t));
}
开发者ID:genorm,项目名称:folly,代码行数:9,代码来源:InterruptTest.cpp

示例4: after

void after(uv_async_t *handle, int status)
{
	pthread_mutex_lock(&queue_mutex);
	Baton *baton = queue_msg.front();
	queue_msg.pop();
	pthread_mutex_unlock(&queue_mutex);

	baton->afterCallBack(baton);
}
开发者ID:michielbdejong,项目名称:TransNode,代码行数:9,代码来源:transNode_old.cpp

示例5: TEST_F

TEST_F(EventBaseThreadTest, self_move) {
  EventBaseThread ebt0;
  auto ebt = std::move(ebt0);

  EXPECT_NE(nullptr, ebt.getEventBase());

  Baton<> done;
  ebt.getEventBase()->runInEventBaseThread([&] { done.post(); });
  ASSERT_TRUE(done.try_wait_for(seconds(1)));
}
开发者ID:RcRonco,项目名称:folly,代码行数:10,代码来源:EventBaseThreadTest.cpp

示例6: run_timed_wait_tmo_tests

void run_timed_wait_tmo_tests() {
  Baton<Atom> b;

  auto thr = DSched::thread([&]{
    bool rv = b.timed_wait(Clock::now() + std::chrono::milliseconds(1));
    // main thread is guaranteed to not post until timeout occurs
    EXPECT_FALSE(rv);
  });
  DSched::join(thr);
}
开发者ID:AddictXQ,项目名称:folly,代码行数:10,代码来源:BatonTest.cpp

示例7: TEST_F

TEST_F(FilePollerTest, TestDeleteFile) {
  Baton<> baton;
  bool updated = false;
  createFile();
  FilePoller poller(tmpFile, std::chrono::milliseconds(1));
  poller.addCallback([&]() {
    updated = true;
    baton.post();
  });
  remove(tmpFile.c_str());
  ASSERT_TRUE(baton.timed_wait(std::chrono::seconds(5)));
  ASSERT_TRUE(updated);
}
开发者ID:ImproviseShi,项目名称:fbthrift,代码行数:13,代码来源:FilePollerTest.cpp

示例8: TEST_F

TEST_F(FilePollerTest, TestDeleteFile) {
  Baton<> baton;
  bool updated = false;
  createFile();
  FilePoller poller(milliseconds(1));
  poller.addFileToTrack(tmpFile, [&]() {
    updated = true;
    baton.post();
  });
  PCHECK(remove(tmpFile.c_str()) == 0);
  ASSERT_FALSE(baton.try_wait_for(seconds(1)));
  ASSERT_FALSE(updated);
}
开发者ID:facebook,项目名称:wangle,代码行数:13,代码来源:FilePollerTest.cpp

示例9: TEST_F

TEST_F(ProcessTicketTest, TestUpdateTicketFile) {
  Baton<> baton;
  TLSTicketProcessor processor(ticketFile);
  bool updated = false;
  processor.addCallback([&](TLSTicketKeySeeds) {
    updated = true;
    baton.post();
  });
  CHECK(writeFile(validTicketData, ticketFile.c_str()));
  updateModifiedTime(ticketFile);
  baton.timed_wait(std::chrono::seconds(30));
  ASSERT_TRUE(updated);
}
开发者ID:ConfusedReality,项目名称:pkg_serialization_fbthrift,代码行数:13,代码来源:TLSTicketProcessorTest.cpp

示例10: TEST

TEST(ThreadPoolExecutorTest, DynamicThreadAddRemoveRace) {
  CPUThreadPoolExecutor e(1);
  e.setThreadDeathTimeout(std::chrono::milliseconds(0));
  std::atomic<uint64_t> count{0};
  for (int i = 0; i < 10000; i++) {
    Baton<> b;
    e.add([&]() {
      count.fetch_add(1, std::memory_order_relaxed);
      b.post();
    });
    b.wait();
  }
  e.join();
  EXPECT_EQ(count, 10000);
}
开发者ID:JacobMao,项目名称:folly,代码行数:15,代码来源:ThreadPoolExecutorTest.cpp

示例11: LOG

bool EventBase::runInEventBaseThreadAndWait(Func fn) {
  if (inRunningEventBaseThread()) {
    LOG(ERROR) << "EventBase " << this << ": Waiting in the event loop is not "
               << "allowed";
    return false;
  }

  Baton<> ready;
  runInEventBaseThread([&ready, fn = std::move(fn)]() mutable {
    SCOPE_EXIT {
      ready.post();
    };
    // A trick to force the stored functor to be executed and then destructed
    // before posting the baton and waking the waiting thread.
    copy(std::move(fn))();
  });
开发者ID:RcRonco,项目名称:folly,代码行数:16,代码来源:EventBase.cpp

示例12: run_timed_wait_regular_test

void run_timed_wait_regular_test() {
  Baton<Atom> b;

  auto thr = DSched::thread([&] {
    bool rv = b.timed_wait(
                std::chrono::time_point<std::chrono::system_clock>::max());
    if (std::is_same<Atom<int>, std::atomic<int>>::value) {
      // We can only ensure this for std::atomic
      EXPECT_TRUE(rv);
    }
  });

  if (std::is_same<Atom<int>, std::atomic<int>>::value) {
    // If we are using std::atomic, then a sleep here guarantees to a large
    // extent that 'thr' will execute wait before we post it, thus testing
    // late delivery. For DeterministicAtomic, we just rely on
    // DeterministicSchedule to do the scheduling
    std::this_thread::sleep_for(std::chrono::milliseconds(2));
  }

  b.post();
  DSched::join(thr);
}
开发者ID:15Koala,项目名称:folly,代码行数:23,代码来源:BatonTest.cpp

示例13: TEST

TEST(Baton, basic) {
  Baton<> b;
  b.post();
  b.wait();
}
开发者ID:SamSaffron,项目名称:DiscourseMobile,代码行数:5,代码来源:BatonTest.cpp

示例14: run_try_wait_tests

void run_try_wait_tests() {
  Baton<Atom> b;
  EXPECT_FALSE(b.try_wait());
  b.post();
  EXPECT_TRUE(b.try_wait());
}
开发者ID:15Koala,项目名称:folly,代码行数:6,代码来源:BatonTest.cpp

示例15: run_basic_timed_wait_tests

void run_basic_timed_wait_tests() {
  Baton<Atom> b;
  b.post();
  // tests if early delivery works fine
  EXPECT_TRUE(b.timed_wait(std::chrono::system_clock::now()));
}
开发者ID:15Koala,项目名称:folly,代码行数:6,代码来源:BatonTest.cpp


注:本文中的Baton类示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。