4coder/4ed_log.cpp

58 lines
1.3 KiB
C++
Raw Normal View History

2019-08-16 02:54:06 +00:00
/*
* Mr. 4th Dimention - Allen Webster
*
* 14.08.2019
*
* Core logging implementation.
*
*/
// TOP
global Log global_log = {};
internal void
log_init(void){
global_log.mutex = system_mutex_make();
global_log.arena = make_arena_system();
2019-08-16 02:54:06 +00:00
}
internal b32
log_string(String_Const_u8 str){
b32 result = false;
i32 thread_id = system_thread_get_id();
2019-08-16 02:54:06 +00:00
if (global_log.disabled_thread_id != thread_id){
system_mutex_acquire(global_log.mutex);
2019-08-16 02:54:06 +00:00
string_list_push(&global_log.arena, &global_log.list, push_string_copy(&global_log.arena, str));
system_mutex_release(global_log.mutex);
2019-08-16 02:54:06 +00:00
result = true;
}
return(result);
}
internal void
output_file_append(Models *models, Editing_File *file, String_Const_u8 value);
internal b32
log_flush(Models *models){
b32 result = false;
system_mutex_acquire(global_log.mutex);
global_log.disabled_thread_id = system_thread_get_id();
2019-08-16 02:54:06 +00:00
if (global_log.list.total_size > 0){
String_Const_u8 text = string_list_flatten(&global_log.arena, global_log.list);
output_file_append(models, models->log_buffer, text);
result = true;
}
linalloc_clear(&global_log.arena);
block_zero_struct(&global_log.list);
global_log.disabled_thread_id = 0;
system_mutex_release(global_log.mutex);
2019-08-16 02:54:06 +00:00
return(result);
}
// BOTTOM