Scroom  0.14
anonymous_namespace{threadpoolimpl.cc}::ThreadList Class Reference
Collaboration diagram for anonymous_namespace{threadpoolimpl.cc}::ThreadList:
Collaboration graph

Public Types

using Ptr = boost::shared_ptr< ThreadList >
 

Public Member Functions

void wait ()
 
void add (const ThreadPool::ThreadPtr &t)
 
void add (const boost::shared_ptr< void > &t, const std::string &s)
 

Static Public Member Functions

static Ptr instance ()
 

Private Member Functions

void dumpPointers ()
 

Private Attributes

boost::mutex mut
 
std::list< ThreadPool::ThreadPtrthreads
 
std::list< std::pair< boost::weak_ptr< void >, std::string > > pointers
 

Detailed Description

List of threads to wait for (when terminating)

Member Typedef Documentation

◆ Ptr

using anonymous_namespace{threadpoolimpl.cc}::ThreadList::Ptr = boost::shared_ptr<ThreadList>

Member Function Documentation

◆ add() [1/2]

void anonymous_namespace{threadpoolimpl.cc}::ThreadList::add ( const boost::shared_ptr< void > &  t,
const std::string &  s 
)
175  {
176  boost::mutex::scoped_lock const lock(mut);
177  pointers.push_back(std::make_pair<boost::weak_ptr<void>, std::string>(t, std::string(s)));
178  }

◆ add() [2/2]

void anonymous_namespace{threadpoolimpl.cc}::ThreadList::add ( const ThreadPool::ThreadPtr t)
169  {
170  boost::mutex::scoped_lock const lock(mut);
171  threads.push_back(t);
172  }

◆ dumpPointers()

void anonymous_namespace{threadpoolimpl.cc}::ThreadList::dumpPointers ( )
private
95  {
96  auto cur = pointers.begin();
97  while(cur != pointers.end())
98  {
99  const auto count = cur->first.use_count();
100 
101  if(count)
102  {
103  spdlog::info("{} references to {} remaining", count, cur->second);
104  cur++;
105  }
106  else
107  {
108  cur = pointers.erase(cur);
109  }
110  }
111  }

◆ instance()

ThreadList::Ptr anonymous_namespace{threadpoolimpl.cc}::ThreadList::instance ( )
static
89  {
90  static Ptr const threadList = Ptr(new ThreadList());
91  return threadList;
92  }

◆ wait()

void anonymous_namespace{threadpoolimpl.cc}::ThreadList::wait ( )
114  {
115  const boost::posix_time::millisec short_timeout(1);
116  const boost::posix_time::millisec timeout(250);
117  decltype(threads.size()) count = 0;
118 
119  {
120  boost::mutex::scoped_lock const lock(mut);
121 
122  auto cur = threads.begin();
123  while(cur != threads.end())
124  {
125  if((*cur)->timed_join(short_timeout))
126  {
127  cur = threads.erase(cur);
128  }
129  else
130  {
131  cur++;
132  }
133  }
134 
135  count = threads.size();
136  }
137 
138  int triesRemaining = 256;
139  while(triesRemaining > 0 && count > 0)
140  {
141  boost::mutex::scoped_lock const lock(mut);
142  dumpPointers();
143  spdlog::info("Waiting for {} threads to terminate", count);
144 
145  auto cur = threads.begin();
146  while(cur != threads.end())
147  {
148  if((*cur)->timed_join(timeout))
149  {
150  cur = threads.erase(cur);
151  }
152  else
153  {
154  cur++;
155  }
156  }
157 
158  count = threads.size();
159  triesRemaining--;
160  }
161 
162  if(!threads.empty())
163  {
164  abort();
165  }
166  }
Here is the call graph for this function:

Member Data Documentation

◆ mut

boost::mutex anonymous_namespace{threadpoolimpl.cc}::ThreadList::mut
private

◆ pointers

std::list<std::pair<boost::weak_ptr<void>, std::string> > anonymous_namespace{threadpoolimpl.cc}::ThreadList::pointers
private

◆ threads

std::list<ThreadPool::ThreadPtr> anonymous_namespace{threadpoolimpl.cc}::ThreadList::threads
private

The documentation for this class was generated from the following file:
short_timeout
static const millisec short_timeout(250)
anonymous_namespace{threadpoolimpl.cc}::ThreadList::threads
std::list< ThreadPool::ThreadPtr > threads
Definition: threadpoolimpl.cc:45
Scroom::Utils::Detail::abort
void abort() __attribute__((noreturn))
Definition: assertions.cc:126
anonymous_namespace{threadpoolimpl.cc}::ThreadList::Ptr
boost::shared_ptr< ThreadList > Ptr
Definition: threadpoolimpl.cc:41
anonymous_namespace{threadpoolimpl.cc}::ThreadList::mut
boost::mutex mut
Definition: threadpoolimpl.cc:44
anonymous_namespace{threadpoolimpl.cc}::ThreadList::dumpPointers
void dumpPointers()
Definition: threadpoolimpl.cc:94
anonymous_namespace{threadpoolimpl.cc}::ThreadList::pointers
std::list< std::pair< boost::weak_ptr< void >, std::string > > pointers
Definition: threadpoolimpl.cc:46