log: flush buffers after assert failure

This commit is contained in:
Andrei Alexeyev 2023-03-26 01:07:17 +01:00
parent efe8370845
commit 7c19322940
No known key found for this signature in database
GPG key ID: 72D26128040B9690
4 changed files with 11 additions and 5 deletions

View file

@ -309,7 +309,7 @@ bool dynstage_reload_library(void) {
if(dynstage.lib) {
// In-flight async log messages may still have pointers to static strings inside the old lib
// Wait for them to finish processing so it's safe to unload
log_sync();
log_sync(false);
dlclose(dynstage.lib);
}

View file

@ -452,11 +452,17 @@ void log_shutdown(void) {
memset(&logging, 0, sizeof(logging));
}
void log_sync(void) {
void log_sync(bool flush) {
SDL_LockMutex(logging.queue.mutex);
while(logging.queue.queue.first) {
while(logging.queue.queue.first) {
SDL_CondWait(logging.queue.cond, logging.queue.mutex);
}
if(flush) {
list_foreach(&logging.outputs, sync_logger, NULL);
}
SDL_UnlockMutex(logging.queue.mutex);
}

View file

@ -131,7 +131,7 @@ LogLevelDiff log_merge_level_diff(LogLevelDiff lower, LogLevelDiff upper) attr_n
LogLevel log_apply_level_diff(LogLevel lvls, LogLevelDiff diff) attr_nodiscard;
bool log_initialized(void) attr_nodiscard;
void log_set_gui_error_appendix(const char *message);
void log_sync(void);
void log_sync(bool flush);
void log_add_filter(LogLevelDiff diff, const char *pmod, const char *pfunc);
bool log_add_filter_string(const char *fstr);
void log_remove_filters(void);

View file

@ -17,7 +17,7 @@ void _ts_assert_fail(const char *cond, const char *func, const char *file, int l
if(use_log) {
_taisei_log(LOG_FAKEFATAL, func, file, line, "%s:%i: assertion `%s` failed", file, line, cond);
log_sync();
log_sync(true);
} else {
tsfprintf(stderr, "%s:%i: %s(): assertion `%s` failed\n", file, line, func, cond);
}