mirror of
https://github.com/Z3Prover/z3
synced 2025-04-22 16:45:31 +00:00
Added optional synchronization for multi-thread API logs. Relates to #798.
This commit is contained in:
parent
03f8b871a1
commit
dee7c29b19
2 changed files with 63 additions and 26 deletions
|
@ -26,32 +26,61 @@ std::ostream * g_z3_log = 0;
|
|||
bool g_z3_log_enabled = false;
|
||||
|
||||
extern "C" {
|
||||
Z3_bool Z3_API Z3_open_log(Z3_string filename) {
|
||||
if (g_z3_log != 0)
|
||||
Z3_close_log();
|
||||
g_z3_log = alloc(std::ofstream, filename);
|
||||
g_z3_log_enabled = true;
|
||||
if (g_z3_log->bad() || g_z3_log->fail()) {
|
||||
dealloc(g_z3_log);
|
||||
g_z3_log = 0;
|
||||
return Z3_FALSE;
|
||||
}
|
||||
*g_z3_log << "V \"" << Z3_MAJOR_VERSION << "." << Z3_MINOR_VERSION << "." << Z3_BUILD_NUMBER << "." << Z3_REVISION_NUMBER << " " << __DATE__ << "\"\n";
|
||||
g_z3_log->flush();
|
||||
return Z3_TRUE;
|
||||
}
|
||||
|
||||
void Z3_API Z3_append_log(Z3_string str) {
|
||||
if (g_z3_log == 0)
|
||||
return;
|
||||
_Z3_append_log(static_cast<char const *>(str));
|
||||
}
|
||||
|
||||
void Z3_API Z3_close_log(void) {
|
||||
void Z3_close_log_unsafe(void) {
|
||||
if (g_z3_log != 0) {
|
||||
dealloc(g_z3_log);
|
||||
g_z3_log_enabled = false;
|
||||
g_z3_log = 0;
|
||||
}
|
||||
}
|
||||
|
||||
Z3_bool Z3_API Z3_open_log(Z3_string filename) {
|
||||
#ifdef Z3_LOG_SYNC
|
||||
#pragma omp critical (z3_log)
|
||||
{
|
||||
#endif
|
||||
if (g_z3_log != 0)
|
||||
Z3_close_log_unsafe();
|
||||
g_z3_log = alloc(std::ofstream, filename);
|
||||
if (g_z3_log->bad() || g_z3_log->fail()) {
|
||||
dealloc(g_z3_log);
|
||||
g_z3_log = 0;
|
||||
return Z3_FALSE;
|
||||
}
|
||||
*g_z3_log << "V \"" << Z3_MAJOR_VERSION << "." << Z3_MINOR_VERSION << "." << Z3_BUILD_NUMBER << "." << Z3_REVISION_NUMBER << " " << __DATE__ << "\"\n";
|
||||
g_z3_log->flush();
|
||||
g_z3_log_enabled = true;
|
||||
#ifdef Z3_LOG_SYNC
|
||||
}
|
||||
#endif
|
||||
return Z3_TRUE;
|
||||
}
|
||||
|
||||
void Z3_API Z3_append_log(Z3_string str) {
|
||||
if (g_z3_log == 0)
|
||||
return;
|
||||
#ifdef Z3_LOG_SYNC
|
||||
#pragma omp critical (z3_log)
|
||||
{
|
||||
#endif
|
||||
if (g_z3_log == 0)
|
||||
return;
|
||||
_Z3_append_log(static_cast<char const *>(str));
|
||||
#ifdef Z3_LOG_SYNC
|
||||
}
|
||||
#endif
|
||||
}
|
||||
|
||||
void Z3_API Z3_close_log(void) {
|
||||
if (g_z3_log != 0) {
|
||||
#ifdef Z3_LOG_SYNC
|
||||
#pragma omp critical (z3_log)
|
||||
{
|
||||
#endif
|
||||
Z3_close_log_unsafe();
|
||||
#ifdef Z3_LOG_SYNC
|
||||
}
|
||||
#endif
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue