mirror of
https://github.com/RT-Thread/rt-thread.git
synced 2025-12-29 02:20:21 +00:00
sync smart & dfs (#8672)
Signed-off-by: xqyjlj <xqyjlj@126.com> Signed-off-by: Shell <smokewood@qq.com> Co-authored-by: xqyjlj <xqyjlj@126.com>
This commit is contained in:
@@ -18,7 +18,7 @@ typedef rt_ubase_t rt_bitmap_t;
|
||||
#define RT_BITMAP_BITS_MIN (sizeof(rt_bitmap_t) * 8)
|
||||
#define RT_BITMAP_LEN(bits) (((bits) + (RT_BITMAP_BITS_MIN) - 1) / (RT_BITMAP_BITS_MIN))
|
||||
#define RT_BITMAP_BIT_LEN(nr) (nr * RT_BITMAP_BITS_MIN)
|
||||
#define RT_DECLARE_BITMAP(name, bits) rt_bitmap_t name[RT_BITMAP_LEN(bits)]
|
||||
#define RT_BITMAP_DECLARE(name, bits) rt_bitmap_t name[RT_BITMAP_LEN(bits)]
|
||||
|
||||
rt_inline void rt_bitmap_set_bit(rt_bitmap_t *bitmap, rt_uint32_t bit)
|
||||
{
|
||||
|
||||
@@ -3,6 +3,10 @@ from building import *
|
||||
cwd = GetCurrentDir()
|
||||
src = Glob('*.c')
|
||||
CPPPATH = [cwd]
|
||||
|
||||
if GetDepend('RT_USING_ADT_BITMAP') == False:
|
||||
SrcRemove(src, ['rid_bitmap.c'])
|
||||
|
||||
group = DefineGroup('Utilities', src, depend = ['RT_USING_RESOURCE_ID'], CPPPATH = CPPPATH)
|
||||
|
||||
Return('group')
|
||||
|
||||
116
components/utilities/resource/rid_bitmap.c
Normal file
116
components/utilities/resource/rid_bitmap.c
Normal file
@@ -0,0 +1,116 @@
|
||||
/*
|
||||
* Copyright (c) 2006-2023, RT-Thread Development Team
|
||||
*
|
||||
* SPDX-License-Identifier: Apache-2.0
|
||||
*
|
||||
* Change Logs:
|
||||
* Date Author Notes
|
||||
* 2023-12-07 Shell First version
|
||||
*/
|
||||
|
||||
#include "rid_bitmap.h"
|
||||
#include <bitmap.h>
|
||||
#include <rtdef.h>
|
||||
|
||||
void rid_bitmap_init(rid_bitmap_t mgr, int min_id, int total_id_count,
|
||||
rt_bitmap_t *set, struct rt_mutex *id_lock)
|
||||
{
|
||||
mgr->min_id = min_id;
|
||||
mgr->total_id_count = total_id_count;
|
||||
mgr->bitset = set;
|
||||
mgr->id_lock = id_lock;
|
||||
|
||||
return;
|
||||
}
|
||||
|
||||
long rid_bitmap_get(rid_bitmap_t mgr)
|
||||
{
|
||||
long id;
|
||||
long overflow;
|
||||
if (mgr->id_lock)
|
||||
{
|
||||
rt_mutex_take(mgr->id_lock, RT_WAITING_FOREVER);
|
||||
}
|
||||
|
||||
overflow = mgr->total_id_count;
|
||||
id = rt_bitmap_next_clear_bit(mgr->bitset, 0, overflow);
|
||||
if (id == overflow)
|
||||
{
|
||||
id = -1;
|
||||
}
|
||||
else
|
||||
{
|
||||
rt_bitmap_set_bit(mgr->bitset, id);
|
||||
id += mgr->min_id;
|
||||
}
|
||||
|
||||
if (mgr->id_lock)
|
||||
{
|
||||
rt_mutex_release(mgr->id_lock);
|
||||
}
|
||||
return id;
|
||||
}
|
||||
|
||||
long rid_bitmap_get_named(rid_bitmap_t mgr, long no)
|
||||
{
|
||||
long id_relative;
|
||||
long overflow;
|
||||
long min;
|
||||
|
||||
if (mgr->id_lock)
|
||||
{
|
||||
rt_mutex_take(mgr->id_lock, RT_WAITING_FOREVER);
|
||||
}
|
||||
|
||||
min = mgr->min_id;
|
||||
id_relative = no - min;
|
||||
overflow = mgr->total_id_count;
|
||||
if (id_relative >= min && id_relative < overflow)
|
||||
{
|
||||
if (rt_bitmap_test_bit(mgr->bitset, id_relative))
|
||||
{
|
||||
id_relative = -RT_EBUSY;
|
||||
}
|
||||
else
|
||||
{
|
||||
rt_bitmap_set_bit(mgr->bitset, id_relative);
|
||||
id_relative += min;
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
id_relative = -1;
|
||||
}
|
||||
|
||||
if (mgr->id_lock)
|
||||
{
|
||||
rt_mutex_release(mgr->id_lock);
|
||||
}
|
||||
return id_relative;
|
||||
}
|
||||
|
||||
void rid_bitmap_put(rid_bitmap_t mgr, long no)
|
||||
{
|
||||
long id_relative;
|
||||
long overflow;
|
||||
long min;
|
||||
|
||||
if (mgr->id_lock)
|
||||
{
|
||||
rt_mutex_take(mgr->id_lock, RT_WAITING_FOREVER);
|
||||
}
|
||||
|
||||
min = mgr->min_id;
|
||||
id_relative = no - min;
|
||||
overflow = mgr->total_id_count;
|
||||
if (id_relative >= min && id_relative < overflow &&
|
||||
rt_bitmap_test_bit(mgr->bitset, id_relative))
|
||||
{
|
||||
rt_bitmap_clear_bit(mgr->bitset, id_relative);
|
||||
}
|
||||
|
||||
if (mgr->id_lock)
|
||||
{
|
||||
rt_mutex_release(mgr->id_lock);
|
||||
}
|
||||
}
|
||||
34
components/utilities/resource/rid_bitmap.h
Normal file
34
components/utilities/resource/rid_bitmap.h
Normal file
@@ -0,0 +1,34 @@
|
||||
/*
|
||||
* Copyright (c) 2006-2023, RT-Thread Development Team
|
||||
*
|
||||
* SPDX-License-Identifier: Apache-2.0
|
||||
*
|
||||
* Change Logs:
|
||||
* Date Author Notes
|
||||
* 2023-12-07 Shell First version
|
||||
*/
|
||||
|
||||
#ifndef __RID_BITMAP_H__
|
||||
#define __RID_BITMAP_H__
|
||||
|
||||
#include <rthw.h>
|
||||
#include <rtthread.h>
|
||||
#include <bitmap.h>
|
||||
|
||||
#define RESOURCE_ID_INIT {0}
|
||||
|
||||
typedef struct rid_bitmap
|
||||
{
|
||||
struct rt_mutex *id_lock;
|
||||
long min_id;
|
||||
long total_id_count;
|
||||
rt_bitmap_t *bitset;
|
||||
} *rid_bitmap_t;
|
||||
|
||||
void rid_bitmap_init(rid_bitmap_t mgr, int min_id, int total_id_count,
|
||||
rt_bitmap_t *set, struct rt_mutex *id_lock);
|
||||
long rid_bitmap_get(rid_bitmap_t mgr);
|
||||
long rid_bitmap_get_named(rid_bitmap_t mgr, long no);
|
||||
void rid_bitmap_put(rid_bitmap_t mgr, long no);
|
||||
|
||||
#endif /* __RID_BITMAP_H__ */
|
||||
@@ -1272,7 +1272,7 @@ rt_err_t ulog_backend_register(ulog_backend_t backend, const char *name, rt_bool
|
||||
|
||||
backend->support_color = support_color;
|
||||
backend->out_level = LOG_FILTER_LVL_ALL;
|
||||
rt_strncpy(backend->name, name, RT_NAME_MAX);
|
||||
rt_strncpy(backend->name, name, RT_NAME_MAX - 1);
|
||||
|
||||
level = rt_spin_lock_irqsave(&_spinlock);
|
||||
rt_slist_append(&ulog.backend_list, &backend->list);
|
||||
|
||||
Reference in New Issue
Block a user