3
0
Fork 0
mirror of https://github.com/Z3Prover/z3 synced 2025-06-06 06:03:23 +00:00

add stub for finalize

Signed-off-by: Nikolaj Bjorner <nbjorner@microsoft.com>
This commit is contained in:
Nikolaj Bjorner 2020-10-22 11:07:05 -07:00
parent 0301d2e05e
commit 9bd7df7e19
4 changed files with 22 additions and 12 deletions

View file

@ -65,6 +65,7 @@ z3_add_component(util
MEMORY_INIT_FINALIZER_HEADERS MEMORY_INIT_FINALIZER_HEADERS
debug.h debug.h
gparams.h gparams.h
scoped_timer.h
prime_generator.h prime_generator.h
rational.h rational.h
rlimit.h rlimit.h

View file

@ -21,19 +21,19 @@ Revision History:
#include "util/scoped_timer.h" #include "util/scoped_timer.h"
#include "util/util.h" #include "util/util.h"
#include "util/vector.h"
#include <chrono> #include <chrono>
#include <climits> #include <climits>
#include <condition_variable> #include <condition_variable>
#include <mutex> #include <mutex>
#include <thread> #include <thread>
#include <vector>
struct state { struct state {
std::thread * m_thread = nullptr; std::thread * m_thread { nullptr };
std::timed_mutex m_mutex; std::timed_mutex m_mutex;
unsigned ms; unsigned ms { 0 };
event_handler * eh; event_handler * eh { nullptr };
int work = 0; int work { 0 };
std::condition_variable_any cv; std::condition_variable_any cv;
}; };
@ -43,7 +43,7 @@ struct state {
* destructing threads blocked on condition variables leads to * destructing threads blocked on condition variables leads to
* deadlock. * deadlock.
*/ */
static std::vector<state *> available_workers; static ptr_vector<state> available_workers;
static std::mutex workers; static std::mutex workers;
static void thread_func(state *s) { static void thread_func(state *s) {
@ -80,7 +80,8 @@ public:
if (available_workers.empty()) { if (available_workers.empty()) {
workers.unlock(); workers.unlock();
s = new state; s = new state;
} else { }
else {
s = available_workers.back(); s = available_workers.back();
available_workers.pop_back(); available_workers.pop_back();
workers.unlock(); workers.unlock();
@ -92,7 +93,8 @@ public:
if (!s->m_thread) { if (!s->m_thread) {
s->m_thread = new std::thread(thread_func, s); s->m_thread = new std::thread(thread_func, s);
s->m_thread->detach(); s->m_thread->detach();
} else { }
else {
s->cv.notify_one(); s->cv.notify_one();
} }
} }
@ -112,3 +114,9 @@ scoped_timer::scoped_timer(unsigned ms, event_handler * eh) {
scoped_timer::~scoped_timer() { scoped_timer::~scoped_timer() {
dealloc(m_imp); dealloc(m_imp);
} }
void finalize_scoped_timer() {
// TODO: stub to collect idle allocated timers.
// if a timer is not idle, we treat this as abnormal
// termination and don't commit to collecting the state.
}

View file

@ -28,3 +28,8 @@ public:
~scoped_timer(); ~scoped_timer();
}; };
/*
ADD_FINALIZER('finalize_scoped_timer();')
*/
void finalize_scoped_timer();

View file

@ -16,9 +16,6 @@ Author:
Revision History: Revision History:
--*/ --*/
#if 0
// include "util/new_symbol.h"
#else
#pragma once #pragma once
#include <climits> #include <climits>
#include <string> #include <string>
@ -156,5 +153,4 @@ void finalize_symbols();
// two non-numerical symbols are compared using string comparison. // two non-numerical symbols are compared using string comparison.
bool lt(symbol const & s1, symbol const & s2); bool lt(symbol const & s1, symbol const & s2);
#endif /* SYMBOL_H_ */