Skip to content

Commit c463af9

Browse files
committed
Add Dmod_GetLogLevel function to retrieve effective log level with context caching
1 parent c304cc6 commit c463af9

2 files changed

Lines changed: 29 additions & 26 deletions

File tree

inc/dmod_module.h

Lines changed: 0 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -7,32 +7,6 @@ extern "C" {
77

88
#include "dmod_defs.h"
99
#include "dmod_types.h"
10-
#include "dmod_sal.h"
11-
12-
/**
13-
* @brief Get the effective log level for the current module
14-
*
15-
* On the first call the module context is looked up via
16-
* Dmod_GetModuleContext() using the module name supplied by
17-
* Dmod_GetCurrentModuleName(), and the result is cached in a static
18-
* variable. Subsequent calls skip the lookup entirely.
19-
*
20-
* A critical section guards the initialization to prevent concurrent
21-
* first-call races.
22-
*/
23-
static inline Dmod_LogLevel_t Dmod_GetLogLevel(void)
24-
{
25-
static volatile Dmod_Context_t* s_ctx = NULL;
26-
27-
Dmod_EnterCritical();
28-
if( s_ctx == NULL )
29-
{
30-
s_ctx = Dmod_GetModuleContext(Dmod_GetCurrentModuleName());
31-
}
32-
Dmod_ExitCritical();
33-
34-
return Dmod_GetModuleLogLevel(s_ctx);
35-
}
3610

3711
#ifdef __cplusplus
3812
}

inc/dmod_sal.h

Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -50,6 +50,7 @@ extern "C" {
5050
#include "dmod_types.h"
5151
#include <stdarg.h>
5252

53+
5354
//==============================================================================
5455
// FUNCTION PROTOTYPES
5556
//==============================================================================
@@ -177,6 +178,34 @@ DMOD_BUILTIN_API(Dmod, 1.0, const char*, _GetCurrentModuleNameEx, ( const char*
177178
* @addtogroup DMOD_SAL_DEBUG
178179
* @{
179180
*/
181+
182+
#ifdef DMOD_MODULE_NAME
183+
/**
184+
* @brief Get the effective log level for the current module
185+
*
186+
* On the first call the module context is looked up via
187+
* Dmod_GetModuleContext() using the module name supplied by
188+
* Dmod_GetCurrentModuleName(), and the result is cached in a static
189+
* variable. Subsequent calls skip the lookup entirely.
190+
*
191+
* A critical section guards the initialization to prevent concurrent
192+
* first-call races.
193+
*/
194+
static inline Dmod_LogLevel_t Dmod_GetLogLevel(void)
195+
{
196+
static volatile Dmod_Context_t* s_ctx = NULL;
197+
198+
Dmod_EnterCritical();
199+
if( s_ctx == NULL )
200+
{
201+
s_ctx = Dmod_GetModuleContext(Dmod_GetCurrentModuleName());
202+
}
203+
Dmod_ExitCritical();
204+
205+
return Dmod_GetModuleLogLevel(s_ctx);
206+
}
207+
#endif
208+
180209
DMOD_BUILTIN_API( Dmod, 1.0, bool ,_CheckLogLevel, ( Dmod_LogLevel_t LogLevel ) );
181210
DMOD_BUILTIN_API( Dmod, 1.0, int ,_Printf, ( const char* Format, ... ) );
182211
DMOD_BUILTIN_API( Dmod, 1.0, int ,_FPrintf, ( void* File, const char* Format, ... ) );

0 commit comments

Comments
 (0)