mirror of
https://github.com/nyanmisaka/mpp.git
synced 2025-09-26 21:15:53 +08:00
fix[mpp_singleton]: fix init order issue
Platform: General Spec: all Error case: Constructors may be added after 65535(mpp_singleton_init) ex: mpp_platform added after 65535 when mpp_soc is refactored to c Signed-off-by: Hongjin Li <vic.hong@rock-chips.com> Signed-off-by: xiaoxu.chen <xiaoxu.chen@rock-chips.com> Change-Id: If736904beb0cd64a3e4ae3b20fd72e1198646ac7
This commit is contained in:
@@ -313,7 +313,7 @@ void CONCAT_US(KMPP_OBJ_NAME, unregister)(void)
|
|||||||
KMPP_OBJ_DBG_LOG("unregister leave\n");
|
KMPP_OBJ_DBG_LOG("unregister leave\n");
|
||||||
}
|
}
|
||||||
|
|
||||||
MPP_SINGLETON(KMPP_OBJ_SGLN_ID, TO_STR(KMPP_OBJ_NAME), CONCAT_US(KMPP_OBJ_NAME, register), CONCAT_US(KMPP_OBJ_NAME, unregister));
|
MPP_SINGLETON(KMPP_OBJ_SGLN_ID, KMPP_OBJ_NAME, CONCAT_US(KMPP_OBJ_NAME, register), CONCAT_US(KMPP_OBJ_NAME, unregister));
|
||||||
|
|
||||||
rk_s32 CONCAT_US(KMPP_OBJ_NAME, size)(void)
|
rk_s32 CONCAT_US(KMPP_OBJ_NAME, size)(void)
|
||||||
{
|
{
|
||||||
|
@@ -14,7 +14,8 @@
|
|||||||
|
|
||||||
#include "kmpp_obj.h"
|
#include "kmpp_obj.h"
|
||||||
|
|
||||||
#define TO_STR(x) #x
|
#define _TO_STR(x) #x
|
||||||
|
#define TO_STR(x) _TO_STR(x)
|
||||||
|
|
||||||
/* concat by underscore */
|
/* concat by underscore */
|
||||||
#define CONCAT_US1(a) a
|
#define CONCAT_US1(a) a
|
||||||
|
@@ -42,26 +42,31 @@ typedef struct MppSingletonInfo_t {
|
|||||||
void (*deinit)(void);
|
void (*deinit)(void);
|
||||||
} MppSingletonInfo;
|
} MppSingletonInfo;
|
||||||
|
|
||||||
|
#define SNGL_TO_STR(x) #x
|
||||||
|
#define SNGL_TO_FUNC(x) __mpp_singleton_add_##x
|
||||||
|
/* warning: constructor priorities from 0 to 100 are reserved for the implementation */
|
||||||
|
#define SNGL_BASE_ID 101
|
||||||
#define MPP_SINGLETON(id, name, init, deinit) \
|
#define MPP_SINGLETON(id, name, init, deinit) \
|
||||||
__attribute__((constructor)) \
|
/* increase id from base id to avoid compiler warning */ \
|
||||||
static void __mpp_singleton_add(void) { \
|
__attribute__((constructor(SNGL_BASE_ID + id))) \
|
||||||
|
static void SNGL_TO_FUNC(name)(void) { \
|
||||||
MppSingletonInfo info = { \
|
MppSingletonInfo info = { \
|
||||||
id, \
|
id, \
|
||||||
name, \
|
SNGL_TO_STR(name), \
|
||||||
init, \
|
init, \
|
||||||
deinit, \
|
deinit, \
|
||||||
}; \
|
}; \
|
||||||
mpp_singleton_add(&info); \
|
mpp_singleton_add(&info, __FUNCTION__); \
|
||||||
}
|
}
|
||||||
|
|
||||||
#ifdef __cplusplus
|
#ifdef __cplusplus
|
||||||
extern "C" {
|
extern "C" {
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
rk_s32 mpp_singleton_add(MppSingletonInfo *info);
|
rk_s32 mpp_singleton_add(MppSingletonInfo *info, const char *caller);
|
||||||
|
|
||||||
#ifdef __cplusplus
|
#ifdef __cplusplus
|
||||||
}
|
}
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
#endif /* __MPP_SINGLETON_H__ */
|
#endif /* __MPP_SINGLETON_H__ */
|
||||||
|
@@ -21,29 +21,29 @@ static MppSingletonInfo sgln_info[MPP_SGLN_MAX_CNT] = {0};
|
|||||||
static rk_u64 sgln_mask = 0;
|
static rk_u64 sgln_mask = 0;
|
||||||
static rk_u32 sgln_debug = 0;
|
static rk_u32 sgln_debug = 0;
|
||||||
|
|
||||||
rk_s32 mpp_singleton_add(MppSingletonInfo *info)
|
rk_s32 mpp_singleton_add(MppSingletonInfo *info, const char *caller)
|
||||||
{
|
{
|
||||||
mpp_env_get_u32("mpp_sgln_debug", &sgln_debug, 0);
|
mpp_env_get_u32("mpp_sgln_debug", &sgln_debug, 0);
|
||||||
|
|
||||||
if (!info) {
|
if (!info) {
|
||||||
sgln_dbg("can not add NULL info\n");
|
sgln_dbg("can not add NULL info at %s\n", caller);
|
||||||
return rk_nok;
|
return rk_nok;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (info->id >= MPP_SGLN_MAX_CNT) {
|
if (info->id >= MPP_SGLN_MAX_CNT) {
|
||||||
sgln_dbg("id %d larger than max %d\n", info->id, MPP_SGLN_MAX_CNT);
|
sgln_dbg("id %d larger than max %d at %s\n", info->id, MPP_SGLN_MAX_CNT, caller);
|
||||||
return rk_nok;
|
return rk_nok;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (sgln_mask & (1 << info->id)) {
|
if (sgln_mask & (1 << info->id)) {
|
||||||
sgln_dbg("info %d has been registered\n", info->id);
|
sgln_dbg("info %d has been registered at %s\n", info->id, caller);
|
||||||
return rk_nok;
|
return rk_nok;
|
||||||
}
|
}
|
||||||
|
|
||||||
sgln_info[info->id] = *info;
|
sgln_info[info->id] = *info;
|
||||||
sgln_mask |= (1 << info->id);
|
sgln_mask |= (1 << info->id);
|
||||||
|
|
||||||
sgln_dbg("info %d %s registered\n", info->id, info->name);
|
sgln_dbg("info %2d %-12s registered at %s\n", info->id, info->name, caller);
|
||||||
|
|
||||||
return rk_ok;
|
return rk_ok;
|
||||||
}
|
}
|
||||||
@@ -60,9 +60,9 @@ static void mpp_singleton_deinit(void)
|
|||||||
MppSingletonInfo *info = &sgln_info[i];
|
MppSingletonInfo *info = &sgln_info[i];
|
||||||
|
|
||||||
if (info->deinit) {
|
if (info->deinit) {
|
||||||
sgln_dbg("info %d %s deinit start\n", info->id, info->name);
|
sgln_dbg("info %2d %-12s deinit start\n", info->id, info->name);
|
||||||
info->deinit();
|
info->deinit();
|
||||||
sgln_dbg("info %d %s deinit finish\n", info->id, info->name);
|
sgln_dbg("info %2d %-12s deinit finish\n", info->id, info->name);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -84,9 +84,9 @@ __attribute__((constructor(65535))) static void mpp_singleton_init(void)
|
|||||||
MppSingletonInfo *info = &sgln_info[i];
|
MppSingletonInfo *info = &sgln_info[i];
|
||||||
|
|
||||||
if (info->init) {
|
if (info->init) {
|
||||||
sgln_dbg("info %d %s init start\n", info->id, info->name);
|
sgln_dbg("info %2d %-12s init start\n", info->id, info->name);
|
||||||
info->init();
|
info->init();
|
||||||
sgln_dbg("info %d %s init finish\n", info->id, info->name);
|
sgln_dbg("info %2d %-12s init finish\n", info->id, info->name);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
Reference in New Issue
Block a user