Ejemplo n.º 1
0
SlotInformationStackLocation::SlotInformationStackLocation(SlotInformationStumpBase& stump, const void* pObj, size_t extent) :
  stump(stump),
  pObj(pObj),
  extent(extent),
  prior(*tss)
{
  tss.reset(this);
}
TEST_F(AutowiringUtilitiesTest, ThreadSpecificPtr) {
  AutoCreateContext ctxt;
  CurrentContextPusher pshr(ctxt);
  
  AutoRequired<Thread1> thread1;
  AutoRequired<Thread2> thread2;
  
  s_thread_specific_int.reset(new int(5));
  
  ctxt->Initiate();
  
  std::this_thread::sleep_for(std::chrono::milliseconds(50));
  
  EXPECT_EQ(5, *s_thread_specific_int);
  AutoCurrentContext()->SignalShutdown(true);
}
Ejemplo n.º 3
0
SlotInformationStackLocation::~SlotInformationStackLocation(void) {
  // Replace the prior stack location, we were pushed
  tss.reset(&prior);

  const SlotInformation* p = nullptr;
  if (!stump.pHead.compare_exchange_strong(p, m_pCur, std::memory_order_acquire)) {
    // Failed the exchange, destroy
    std::unique_ptr<SlotInformation> prior;
    for (const auto* cur = m_pCur; cur; cur = cur->pFlink)
      prior.reset(m_pCur);
  }
  ///else
    // Exchange passed, the destination now owns this pointer

  // Unconditionally update to true, no CAS needed
  stump.bInitialized = true;
}
Ejemplo n.º 4
0
TEST_F(AutowiringUtilitiesTest, ThreadSpecificPtr) {
  AutoCreateContext ctxt;
  CurrentContextPusher pshr(ctxt);
  
  AutoRequired<Thread1> thread1;
  AutoRequired<Thread2> thread2;
  
  s_thread_specific_int.reset(new int(5));
  
  ctxt->Initiate();
  
  auto limit = std::chrono::high_resolution_clock::now() + std::chrono::seconds(10);
  while(std::chrono::high_resolution_clock::now() < limit)
    if(5 == *s_thread_specific_int)
      return;
 
  FAIL() << "Thread specific pointer did not increment to the destination value in a timely fashion";
}
 virtual void Run() {
   s_thread_specific_int.reset(new int(3));
   std::this_thread::sleep_for(std::chrono::milliseconds(50));
   EXPECT_EQ(3, *s_thread_specific_int);
 }