From 9f1f9ce9d52fba6b0a8670ce776a94990d3a6103 Mon Sep 17 00:00:00 2001 From: anton98i <12586459+anton98i@users.noreply.github.com> Date: Thu, 21 Oct 2021 15:35:58 +0200 Subject: [PATCH] remove_log_entry_bin_for_thread --- src/dm_logger.vala | 37 +++++++++++++++++++++++++++++++++++++ 1 file changed, 37 insertions(+) diff --git a/src/dm_logger.vala b/src/dm_logger.vala index 05e26b8..b6a5746 100644 --- a/src/dm_logger.vala +++ b/src/dm_logger.vala @@ -10,6 +10,7 @@ namespace DMLogger public static const uint16 LOG_ENTRY_RECORD_TYPE_HINT = 5; public static const uint16 LOG_ENTRY_RECORD_TYPE_FLUSH = 6; public static const uint16 LOG_ENTRY_RECORD_TYPE_TID_ENTRY_BIN = 7; + public static const uint16 LOG_ENTRY_RECORD_TYPE_REMOVE_TID_ENTRY_BIN = 8; public static const uint16 LOG_ENTRY_NONE = 0; public static const uint16 LOG_ENTRY_DEBUG = 1; @@ -261,6 +262,17 @@ namespace DMLogger this.parameters = { }; } + /** + * Creates a new LogEntry with the record type @see DMLogger.LOG_ENTRY_RECORD_TYPE_REMOVE_TID_ENTRY_BIN. + * Is used to execute the method @see Logger.remove_log_entry_bin_for_thread in a thread-safe way. + */ + public LogEntry.remove_tid_entry_bin( ) + { + this( 0, "", 0, LOG_ENTRY_NONE, 0, 0, false ); + this.record_type = LOG_ENTRY_RECORD_TYPE_REMOVE_TID_ENTRY_BIN; + this.parameters = { }; + } + /** * Parses the given message and inserts the given parameters into it. * @param _message The message to be parsed. @@ -714,6 +726,25 @@ namespace DMLogger } } + /** + * Removes the Thread-ID of the tid_entry_bin hash table. + * + * @param tid the ID of the Thread + * @param thread_safe If the DMLogger was started threaded, this parameter states if the log entry bin creation + * should be done in a thread-safe way ( via the @see DMLogger.log_queue ) or immediately. + */ + public void remove_log_entry_bin_for_thread( uint64 tid, bool thread_safe = true ) + { + if ( this.threaded && thread_safe ) + { + DMLogger.log_queue.push( new LogEntry.remove_tid_entry_bin( ) ); + } + else + { + DMLogger.log.tid_entry_bin.remove( OpenDMLib.gettid( ) ); + } + } + /** * This method can be used to set the FileStream which should be used when printing out messages. * @param out_stream The new FileStream which should be used. @@ -743,6 +774,12 @@ namespace DMLogger continue; } + if ( ( (!)e ).record_type == LOG_ENTRY_RECORD_TYPE_REMOVE_TID_ENTRY_BIN ) + { + this.remove_log_entry_bin_for_thread( e.tid, false ); + continue; + } + if ( ( (!)e ).record_type == LOG_ENTRY_RECORD_TYPE_FLUSH ) { if ( this.tid_entry_bin != null && this.tid_entry_bin.get( e.tid ) != null )