mirror of
https://github.com/Z3Prover/z3
synced 2025-04-10 19:27:06 +00:00
scoped_timer: skip extra unneded heap allocation
This commit is contained in:
parent
fc558d3946
commit
db04ccb137
|
@ -34,7 +34,7 @@ Revision History:
|
|||
#endif
|
||||
|
||||
struct scoped_timer_state {
|
||||
std::thread * m_thread { nullptr };
|
||||
std::thread m_thread;
|
||||
std::timed_mutex m_mutex;
|
||||
event_handler * eh;
|
||||
unsigned ms;
|
||||
|
@ -82,9 +82,11 @@ private:
|
|||
public:
|
||||
imp(unsigned ms, event_handler * eh) {
|
||||
workers.lock();
|
||||
bool new_worker = false;
|
||||
if (available_workers.empty()) {
|
||||
workers.unlock();
|
||||
s = new scoped_timer_state;
|
||||
new_worker = true;
|
||||
++num_workers;
|
||||
}
|
||||
else {
|
||||
|
@ -96,8 +98,8 @@ public:
|
|||
s->eh = eh;
|
||||
s->m_mutex.lock();
|
||||
s->work = 1;
|
||||
if (!s->m_thread) {
|
||||
s->m_thread = new std::thread(thread_func, s);
|
||||
if (new_worker) {
|
||||
s->m_thread = std::thread(thread_func, s);
|
||||
}
|
||||
else {
|
||||
s->cv.notify_one();
|
||||
|
@ -146,8 +148,7 @@ void scoped_timer::finalize() {
|
|||
|
||||
for (auto w : cleanup_workers) {
|
||||
++deleted;
|
||||
w->m_thread->join();
|
||||
delete w->m_thread;
|
||||
w->m_thread.join();
|
||||
delete w;
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Reference in a new issue