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


C++ Autowired::NotifyWhenAutowired方法代码示例

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


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

示例1:

TEST_F(PostConstructTest, DelayedNotifyWhenAutowired) {
  // Autorequire, and add a registration:
  bool called = false;
  Autowired<SimpleObject> so;
  so.NotifyWhenAutowired([&called] { called = true; });

  // Inject a type after:
  AutoRequired<SimpleObject>();
  ASSERT_TRUE(called) << "An autowiring notification was not invoked on an already-satisfied field as expected";
}
开发者ID:,项目名称:,代码行数:10,代码来源:

示例2: AutoCurrentContext

TEST_F(PostConstructTest, InjectNotifyWhenAutowired) {
  // Autorequire, and add a registration:
  bool called = false;
  Autowired<Interface3> interface;
  interface.NotifyWhenAutowired([&called] { called = true; });

  // Inject a type after:
  AutoCurrentContext()->Inject<Implementation3>();
  ASSERT_TRUE(called) << "An autowiring notification was not invoked on an already-satisfied field as expected";
}
开发者ID:,项目名称:,代码行数:10,代码来源:

示例3: t

TEST_F(PostConstructTest, NotificationTeardownRace) {
  if (std::thread::hardware_concurrency() == 1)
    return; // Don't bother running on a single-core machine

  std::shared_ptr<CoreContext> pContext;

  auto quit = false;
  auto shouldQuit = MakeAtExit([&quit] { quit = true; });
  std::atomic<size_t> counter{0};

  // This thread sets up the race pathology:
  std::thread t([&] {
    while(!quit) {
      // Barrier until setup time:
      while(counter != 1)
        std::this_thread::yield();

      if(!pContext)
        break;

      // Set the context current, then try to autowire:
      CurrentContextPusher pshr(pContext);
      Autowired<SimpleObject> sobj;
      sobj.NotifyWhenAutowired([] {});

      // Now barrier, and then we will try to race against the context
      // for teardown.
      counter++;
    }
  });

  for(size_t i = 0; i < 200; i++) {
    // Make a new context:
    AutoCreateContext ctxt;
    pContext = ctxt;

    // Wake up the other thread, let it set a notify-when-autowired:
    counter++;
    while(counter != 2)
      std::this_thread::yield();

    // Counter goes back to zero before we make the next loop iteration:
    counter = 0;

    // Now we reset our pContext pointer, and then tell the thread
    // to race with us against context teardown:
    pContext.reset();
  }

  // All done, wait for the thread to back out:
  quit = true;
  counter = 1;
  t.join();
}
开发者ID:,项目名称:,代码行数:54,代码来源:

示例4: while

TEST_F(ContextMemberTest, PathologicalResetCase) {
  Autowired<TypeThatIsNotInjected>* pv;
  volatile std::atomic<size_t> nBarr{ 0 };
  volatile bool proceed = true;
  volatile bool go = false;

  auto resetsV = [&] {
    while(proceed) {
      ++nBarr;
      while (proceed && !go)
        std::this_thread::yield();
      if (!proceed)
        break;

      pv->reset();
      --nBarr;
      while (proceed && go)
        std::this_thread::yield();
    }
  };

  std::thread a{ resetsV };
  std::thread b{ resetsV };

  for (size_t i = 1000; i--;) {
    Autowired<TypeThatIsNotInjected> v;
    pv = &v;
    for (size_t j = 10; j--;)
      v.NotifyWhenAutowired([] {});

    // Bump the threads to spin around:
    while (nBarr != 2)
      std::this_thread::yield();
    go = true;
    while (nBarr)
      std::this_thread::yield();
    go = false;
  }

  proceed = false;
  a.join();
  b.join();
}
开发者ID:codemercenary,项目名称:autowiring,代码行数:43,代码来源:ContextMemberTest.cpp


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