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 467 of file FastTimerService.h.

Constructor & Destructor Documentation

◆ ThreadGuard()

FastTimerService::ThreadGuard::ThreadGuard ( )

Definition at line 1726 of file FastTimerService.cc.

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

1726  {
1727  auto err = ::pthread_key_create(&key_, retire_thread);
1728  if (err) {
1729  throw cms::Exception("FastTimerService") << "ThreadGuard key creation failed: " << ::strerror(err);
1730  }
1731 }
static void retire_thread(void *t)

◆ ~ThreadGuard()

FastTimerService::ThreadGuard::~ThreadGuard ( )
default

Member Function Documentation

◆ finalize()

void FastTimerService::ThreadGuard::finalize ( void  )

Definition at line 1765 of file FastTimerService.cc.

References AlCaHLTBitMon_ParallelJobs::p.

1765  {
1766  for (auto& p : thread_resources_) {
1767  auto expected = true;
1768  if (p->live_.compare_exchange_strong(expected, false)) {
1769  p->measurement_.measure_and_accumulate(p->resource_);
1770  }
1771  }
1772 }
tbb::concurrent_vector< std::shared_ptr< specific_t > > thread_resources_

◆ ptr()

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

Definition at line 1749 of file FastTimerService.cc.

References AlCaHLTBitMon_ParallelJobs::p.

1749  {
1750  return static_cast<std::shared_ptr<specific_t>*>(p);
1751 }

◆ register_thread()

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

Definition at line 1734 of file FastTimerService.cc.

References submitPVResolutionJobs::err, Exception, ALPAKA_ACCELERATOR_NAMESPACE::vertexFinder::it, createTree::pp, and alignCSCRings::r.

Referenced by FastTimerService::on_scheduler_entry().

1734  {
1735  auto ptr = ::pthread_getspecific(key_);
1736 
1737  if (not ptr) {
1738  auto it = thread_resources_.emplace_back(std::make_shared<specific_t>(r));
1739  auto pp = new std::shared_ptr<specific_t>(*it);
1740  auto err = ::pthread_setspecific(key_, pp);
1741  if (err) {
1742  throw cms::Exception("FastTimerService") << "ThreadGuard pthread_setspecific failed: " << ::strerror(err);
1743  }
1744  return true;
1745  }
1746  return false;
1747 }
static std::shared_ptr< specific_t > * ptr(void *p)
tbb::concurrent_vector< std::shared_ptr< specific_t > > thread_resources_

◆ retire_thread()

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

Definition at line 1754 of file FastTimerService.cc.

References AlCaHLTBitMon_ParallelJobs::p.

Referenced by ThreadGuard().

1754  {
1755  auto ps = ptr(p);
1756  auto expected = true;
1757  if ((*ps)->live_.compare_exchange_strong(expected, false)) {
1758  // account any resources used or freed by the thread before leaving the TBB pool
1759  (*ps)->measurement_.measure_and_accumulate((*ps)->resource_);
1760  }
1761  delete ps;
1762 }
static std::shared_ptr< specific_t > * ptr(void *p)

◆ thread()

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

Definition at line 1774 of file FastTimerService.cc.

Referenced by FastTimerService::thread().

1774  {
1775  return (*ptr(::pthread_getspecific(key_)))->measurement_;
1776 }
static std::shared_ptr< specific_t > * ptr(void *p)

Member Data Documentation

◆ key_

pthread_key_t FastTimerService::ThreadGuard::key_

Definition at line 488 of file FastTimerService.h.

Referenced by ThreadGuard().

◆ thread_resources_

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

Definition at line 487 of file FastTimerService.h.