[ulog] Add output locker enabled API

Signed-off-by: armink <armink.ztl@gmail.com>
This commit is contained in:
armink 2021-05-19 18:17:37 +08:00
parent 5ba96109c6
commit e0b9987508
2 changed files with 14 additions and 0 deletions

View File

@ -77,6 +77,7 @@
struct rt_ulog
{
rt_bool_t init_ok;
rt_bool_t output_lock_enabled;
struct rt_semaphore output_locker;
/* all backends */
rt_slist_t backend_list;
@ -186,6 +187,9 @@ size_t ulog_ultoa(char *s, unsigned long int n)
static void output_unlock(void)
{
if (!ulog.output_lock_enabled)
return;
/* is in thread context */
if (rt_interrupt_get_nest() == 0)
{
@ -201,6 +205,9 @@ static void output_unlock(void)
static void output_lock(void)
{
if (!ulog.output_lock_enabled)
return;
/* is in thread context */
if (rt_interrupt_get_nest() == 0)
{
@ -214,6 +221,11 @@ static void output_lock(void)
}
}
void ulog_output_lock_enabled(rt_bool_t enabled)
{
ulog.output_lock_enabled = enabled;
}
static char *get_log_buf(void)
{
/* is in thread context */
@ -1392,6 +1404,7 @@ int ulog_init(void)
return 0;
rt_sem_init(&ulog.output_locker, "ulog lock", 1, RT_IPC_FLAG_FIFO);
ulog.output_lock_enabled = RT_TRUE;
rt_slist_init(&ulog.backend_list);
#ifdef ULOG_USING_FILTER

View File

@ -25,6 +25,7 @@ extern "C" {
*/
int ulog_init(void);
int ulog_async_init(void);
void ulog_output_lock_enabled(rt_bool_t enabled);
void ulog_deinit(void);
/*