CMS 3D CMS Logo

List of all members | Classes | Public Member Functions | Static Public Member Functions | Public Attributes
FastTimerService::ThreadGuard Struct Reference

Classes

struct  specific_t
 

Public Member Functions

void finalize ()
 
bool register_thread (FastTimerService::AtomicResources &r)
 
Measurementthread ()
 
 ThreadGuard ()
 
 ~ThreadGuard ()=default
 

Static Public Member Functions

static std::shared_ptr< specific_t > * ptr (void *p)
 
static void retire_thread (void *t)
 

Public Attributes

pthread_key_t key_
 
tbb::concurrent_vector< std::shared_ptr< specific_t > > thread_resources_
 

Detailed Description

Definition at line 460 of file FastTimerService.h.

Constructor & Destructor Documentation

◆ ThreadGuard()

FastTimerService::ThreadGuard::ThreadGuard ( )

Definition at line 1670 of file FastTimerService.cc.

1670  {
1671  auto err = ::pthread_key_create(&key_, retire_thread);
1672  if (err) {
1673  throw cms::Exception("FastTimerService") << "ThreadGuard key creation failed: " << ::strerror(err);
1674  }
1675 }

References submitPVResolutionJobs::err, Exception, key_, and retire_thread().

◆ ~ThreadGuard()

FastTimerService::ThreadGuard::~ThreadGuard ( )
default

Member Function Documentation

◆ finalize()

void FastTimerService::ThreadGuard::finalize ( void  )

Definition at line 1709 of file FastTimerService.cc.

1709  {
1710  for (auto& p : thread_resources_) {
1711  auto expected = true;
1712  if (p->live_.compare_exchange_strong(expected, false)) {
1713  p->measurement_.measure_and_accumulate(p->resource_);
1714  }
1715  }
1716 }

References AlCaHLTBitMon_ParallelJobs::p.

◆ ptr()

std::shared_ptr< FastTimerService::ThreadGuard::specific_t > * FastTimerService::ThreadGuard::ptr ( void *  p)
static

Definition at line 1693 of file FastTimerService.cc.

1693  {
1694  return static_cast<std::shared_ptr<specific_t>*>(p);
1695 }

References AlCaHLTBitMon_ParallelJobs::p.

◆ register_thread()

bool FastTimerService::ThreadGuard::register_thread ( FastTimerService::AtomicResources r)

Definition at line 1678 of file FastTimerService.cc.

1678  {
1679  auto ptr = ::pthread_getspecific(key_);
1680 
1681  if (not ptr) {
1682  auto p = thread_resources_.emplace_back(std::make_shared<specific_t>(r));
1683  auto pp = new std::shared_ptr<specific_t>(*p);
1684  auto err = ::pthread_setspecific(key_, pp);
1685  if (err) {
1686  throw cms::Exception("FastTimerService") << "ThreadGuard pthread_setspecific failed: " << ::strerror(err);
1687  }
1688  return true;
1689  }
1690  return false;
1691 }

References submitPVResolutionJobs::err, Exception, AlCaHLTBitMon_ParallelJobs::p, createTree::pp, and alignCSCRings::r.

Referenced by FastTimerService::on_scheduler_entry().

◆ retire_thread()

void FastTimerService::ThreadGuard::retire_thread ( void *  t)
static

Definition at line 1698 of file FastTimerService.cc.

1698  {
1699  auto ps = ptr(p);
1700  auto expected = true;
1701  if ((*ps)->live_.compare_exchange_strong(expected, false)) {
1702  // account any resources used or freed by the thread before leaving the TBB pool
1703  (*ps)->measurement_.measure_and_accumulate((*ps)->resource_);
1704  }
1705  delete ps;
1706 }

References AlCaHLTBitMon_ParallelJobs::p.

Referenced by ThreadGuard().

◆ thread()

FastTimerService::Measurement & FastTimerService::ThreadGuard::thread ( )

Definition at line 1718 of file FastTimerService.cc.

1718  {
1719  return (*ptr(::pthread_getspecific(key_)))->measurement_;
1720 }

Referenced by FastTimerService::thread().

Member Data Documentation

◆ key_

pthread_key_t FastTimerService::ThreadGuard::key_

Definition at line 481 of file FastTimerService.h.

Referenced by ThreadGuard().

◆ thread_resources_

tbb::concurrent_vector<std::shared_ptr<specific_t> > FastTimerService::ThreadGuard::thread_resources_

Definition at line 480 of file FastTimerService.h.

FastTimerService::ThreadGuard::retire_thread
static void retire_thread(void *t)
Definition: FastTimerService.cc:1698
AlCaHLTBitMon_ParallelJobs.p
p
Definition: AlCaHLTBitMon_ParallelJobs.py:153
FastTimerService::ThreadGuard::thread_resources_
tbb::concurrent_vector< std::shared_ptr< specific_t > > thread_resources_
Definition: FastTimerService.h:480
submitPVResolutionJobs.err
err
Definition: submitPVResolutionJobs.py:85
alignCSCRings.r
r
Definition: alignCSCRings.py:93
FastTimerService::ThreadGuard::key_
pthread_key_t key_
Definition: FastTimerService.h:481
Exception
Definition: hltDiff.cc:245
createTree.pp
pp
Definition: createTree.py:17
FastTimerService::ThreadGuard::ptr
static std::shared_ptr< specific_t > * ptr(void *p)
Definition: FastTimerService.cc:1693