diff --git a/include/rtthread.h b/include/rtthread.h index 84d34e121302426cb59ee2e6523a19b249a84381..5164b62576d03a1eaea9b7da701a1d4e22f14c87 100644 --- a/include/rtthread.h +++ b/include/rtthread.h @@ -304,9 +304,9 @@ rt_err_t rt_device_control(rt_device_t dev, rt_uint8_t cmd, void* arg); rt_module_t rt_module_load(const rt_uint8_t* name, void* module_ptr); rt_err_t rt_module_unload(rt_module_t module); -rt_module_t rt_module_find(char* name); +rt_err_t rt_module_self_set (rt_module_t module); rt_module_t rt_module_self (void); - +rt_module_t rt_module_find(char* name); #endif /* diff --git a/src/module.c b/src/module.c index c76aafcbd3a45ed448e24413f5840a45b245b968..44a0081d5424c454abed724a181c0365f2a9e938 100644 --- a/src/module.c +++ b/src/module.c @@ -12,9 +12,9 @@ * 2010-01-09 Bernard first version * 2010-04-09 yi.qiu implement based on first version */ - -#include + #include +#include #include "string.h" #include "kservice.h" @@ -35,19 +35,33 @@ #define IS_AX(s) ((s.sh_flags & SHF_ALLOC) && (s.sh_flags & SHF_EXECINSTR)) #define IS_AW(s) ((s.sh_flags & SHF_ALLOC) && (s.sh_flags & SHF_WRITE)) -struct rt_module* rt_current_module; +static struct rt_module* rt_current_module; /** * This function will return self module object * - * @return the self thread object + * @return the self module object * */ rt_module_t rt_module_self (void) { + /* return current module */ return rt_current_module; } +/** + * This function will set current module object + * + * @return RT_EOK + */ +rt_err_t rt_module_set (rt_module_t module) +{ + /* set current module */ + rt_current_module = module; + + return RT_EOK; +} + static int rt_module_arm_relocate(struct rt_module* module, Elf32_Rel *rel, Elf32_Addr sym_val) { Elf32_Addr *where, tmp; @@ -289,6 +303,10 @@ rt_err_t rt_module_unload(rt_module_t module) struct rt_object* object; struct rt_list_node *list, *node; +#ifdef RT_MODULE_DEBUG + rt_kprintf("rt_module_unload %s\n", module->parent.name); +#endif + /* check parameter */ RT_ASSERT(module != RT_NULL); diff --git a/src/object.c b/src/object.c index 559abf72e4835116d9fc4f7cdd9e63e2356bbd02..e8adc60cc29401cf28b859bd8aa7aa8a0a769529 100644 --- a/src/object.c +++ b/src/object.c @@ -21,10 +21,6 @@ #include "kservice.h" -#ifdef RT_USING_MODULE -extern struct rt_module* rt_current_module; -#endif - #define _OBJ_CONTAINER_LIST_INIT(c) \ {&(rt_object_container[c].object_list), &(rt_object_container[c].object_list)} struct rt_object_information rt_object_container[RT_Object_Class_Unknown] = @@ -182,8 +178,8 @@ void rt_object_init(struct rt_object* object, enum rt_object_class_type type, co #ifdef RT_USING_MODULE /* get module object information */ - information = (rt_current_module != RT_NULL) ? - &rt_current_module->module_object[type] : &rt_object_container[type]; + information = (rt_module_self() != RT_NULL) ? + &rt_module_self()->module_object[type] : &rt_object_container[type]; #else /* get object information */ information = &rt_object_container[type]; @@ -261,11 +257,11 @@ rt_object_t rt_object_allocate(enum rt_object_class_type type, const char* name) #ifdef RT_USING_MODULE /* get module object information */ - information = (rt_current_module != RT_NULL) ? - &rt_current_module->module_object[type] : &rt_object_container[type]; + information = (rt_module_self() != RT_NULL) ? + &rt_module_self()->module_object[type] : &rt_module_self()[type]; #else /* get object information */ - information = &rt_object_container[type]; + information = &rt_module_self()[type]; #endif object = (struct rt_object*)rt_malloc(information->object_size); diff --git a/src/scheduler.c b/src/scheduler.c index be712343707a3d8538b9414d9cba08d962a7f40b..d14328febaac3615238619ca3b5e1c890da24dd5 100644 --- a/src/scheduler.c +++ b/src/scheduler.c @@ -38,9 +38,6 @@ rt_list_t rt_thread_priority_table[RT_THREAD_PRIORITY_MAX]; struct rt_thread* rt_current_thread; rt_uint8_t rt_current_priority; -#ifdef RT_USING_MODULE -extern struct rt_module* rt_current_module; -#endif #if RT_THREAD_PRIORITY_MAX > 32 /* maximun priority level, 256 */ @@ -267,8 +264,8 @@ void rt_schedule() rt_current_thread = to_thread; #ifdef RT_USING_MODULE - rt_current_module = (rt_current_thread->module_parent != RT_NULL) ? - rt_current_thread->module_parent : RT_NULL; + rt_module_set ((rt_current_thread->module_parent != RT_NULL) ? + rt_current_thread->module_parent : RT_NULL); #endif #ifdef RT_USING_HOOK diff --git a/src/thread.c b/src/thread.c index 953cf9a0cae115ab41e148c53e2ea77b21e7b976..536189070e080db9d4a9ab6418f4b131f6698918 100644 --- a/src/thread.c +++ b/src/thread.c @@ -32,10 +32,6 @@ extern rt_list_t rt_thread_priority_table[RT_THREAD_PRIORITY_MAX]; extern struct rt_thread* rt_current_thread; extern rt_uint8_t rt_current_priority; -#ifdef RT_USING_MODULE -extern struct rt_module* rt_current_module; -#endif - #ifdef RT_USING_HEAP extern rt_list_t rt_thread_defunct; #endif @@ -82,7 +78,7 @@ static rt_err_t _rt_thread_init(struct rt_thread* thread, #ifdef RT_USING_MODULE /* init module parent */ thread->module_parent = - (rt_current_module != RT_NULL) ? rt_current_module : RT_NULL; + (rt_module_self() != RT_NULL) ? rt_module_self() : RT_NULL; #endif /* init user data */