Scroom 0.14-48-ga0fee447
Loading...
Searching...
No Matches
anonymous_namespace{threadpoolimpl.cc}::ThreadList Class Reference
Collaboration diagram for anonymous_namespace{threadpoolimpl.cc}::ThreadList:
Collaboration graph

Public Types

using Ptr = std::shared_ptr< ThreadList >
 

Public Member Functions

void wait ()
 
void add (const ThreadPool::ThreadPtr &t)
 
void add (const std::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< std::weak_ptr< void >, std::string > > pointers
 
Scroom::Logger logger
 

Detailed Description

List of threads to wait for (when terminating)

Member Typedef Documentation

◆ Ptr

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

Member Function Documentation

◆ add() [1/2]

void anonymous_namespace{threadpoolimpl.cc}::ThreadList::add ( const std::shared_ptr< void > &  t,
const std::string &  s 
)
178 {
179 boost::mutex::scoped_lock const lock(mut);
180 pointers.push_back(std::make_pair<std::weak_ptr<void>, std::string>(t, std::string(s)));
181 }
std::list< std::pair< std::weak_ptr< void >, std::string > > pointers
Definition threadpoolimpl.cc:48
boost::mutex mut
Definition threadpoolimpl.cc:46
ThreadPool t(0)
BitmapSurface::Ptr const s
Definition transformpresentation_test.cc:70

◆ add() [2/2]

void anonymous_namespace{threadpoolimpl.cc}::ThreadList::add ( const ThreadPool::ThreadPtr t)
172 {
173 boost::mutex::scoped_lock const lock(mut);
174 threads.push_back(t);
175 }
std::list< ThreadPool::ThreadPtr > threads
Definition threadpoolimpl.cc:47

◆ dumpPointers()

void anonymous_namespace{threadpoolimpl.cc}::ThreadList::dumpPointers ( )
private
98 {
99 auto cur = pointers.begin();
100 while(cur != pointers.end())
101 {
102 const auto count = cur->first.use_count();
103
104 if(count)
105 {
106 logger->info("{} references to {} remaining", count, cur->second);
107 cur++;
108 }
109 else
110 {
111 cur = pointers.erase(cur);
112 }
113 }
114 }
Scroom::Logger logger
Definition threadpoolimpl.cc:49
const size_t count
Definition pageprovider-tests.cc:21

Referenced by wait().

Here is the caller graph for this function:

◆ instance()

ThreadList::Ptr anonymous_namespace{threadpoolimpl.cc}::ThreadList::instance ( )
static
92 {
93 static Ptr const threadList = std::make_shared<ThreadList>();
94 return threadList;
95 }
std::shared_ptr< ThreadList > Ptr
Definition threadpoolimpl.cc:43

Referenced by ThreadPool::add(), and anonymous_namespace{threadpoolimpl.cc}::NotifyThreadList().

Here is the caller graph for this function:

◆ wait()

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

Member Data Documentation

◆ logger

Scroom::Logger anonymous_namespace{threadpoolimpl.cc}::ThreadList::logger
private

◆ mut

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

◆ pointers

std::list<std::pair<std::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: