CMS 3D CMS Logo

 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Friends Macros Groups Pages
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

FastTimerService::ThreadGuard::ThreadGuard ( )

Definition at line 1669 of file FastTimerService.cc.

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

1669  {
1670  auto err = ::pthread_key_create(&key_, retire_thread);
1671  if (err) {
1672  throw cms::Exception("FastTimerService") << "ThreadGuard key creation failed: " << ::strerror(err);
1673  }
1674 }
static void retire_thread(void *t)
FastTimerService::ThreadGuard::~ThreadGuard ( )
default

Member Function Documentation

void FastTimerService::ThreadGuard::finalize ( void  )

Definition at line 1708 of file FastTimerService.cc.

References AlCaHLTBitMon_ParallelJobs::p.

1708  {
1709  for (auto& p : thread_resources_) {
1710  auto expected = true;
1711  if (p->live_.compare_exchange_strong(expected, false)) {
1712  p->measurement_.measure_and_accumulate(p->resource_);
1713  }
1714  }
1715 }
tbb::concurrent_vector< std::shared_ptr< specific_t > > thread_resources_
std::shared_ptr< FastTimerService::ThreadGuard::specific_t > * FastTimerService::ThreadGuard::ptr ( void *  p)
static

Definition at line 1692 of file FastTimerService.cc.

References AlCaHLTBitMon_ParallelJobs::p.

1692  {
1693  return static_cast<std::shared_ptr<specific_t>*>(p);
1694 }
bool FastTimerService::ThreadGuard::register_thread ( FastTimerService::AtomicResources r)

Definition at line 1677 of file FastTimerService.cc.

References submitPVValidationJobs::err, Exception, AlCaHLTBitMon_ParallelJobs::p, and createTree::pp.

Referenced by FastTimerService::on_scheduler_entry().

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

Definition at line 1697 of file FastTimerService.cc.

Referenced by ThreadGuard().

1697  {
1698  auto ps = ptr(p);
1699  auto expected = true;
1700  if ((*ps)->live_.compare_exchange_strong(expected, false)) {
1701  // account any resources used or freed by the thread before leaving the TBB pool
1702  (*ps)->measurement_.measure_and_accumulate((*ps)->resource_);
1703  }
1704  delete ps;
1705 }
static std::shared_ptr< specific_t > * ptr(void *p)
FastTimerService::Measurement & FastTimerService::ThreadGuard::thread ( )

Definition at line 1717 of file FastTimerService.cc.

Referenced by FastTimerService::thread().

1717  {
1718  return (*ptr(::pthread_getspecific(key_)))->measurement_;
1719 }
static std::shared_ptr< specific_t > * ptr(void *p)

Member Data Documentation

pthread_key_t FastTimerService::ThreadGuard::key_

Definition at line 481 of file FastTimerService.h.

Referenced by ThreadGuard().

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

Definition at line 480 of file FastTimerService.h.