summaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorqiuyiuestc <[email protected]>2010-09-19 23:43:48 +0000
committerqiuyiuestc <[email protected]>2010-09-19 23:43:48 +0000
commit446799244a2b796dbcd83bf8e557aff4ebaadc7d (patch)
treebfff7779005797756a8815a38dcb6db15b043d65 /src
parent3c2c5df6e898ca10107a0c359d8d73e55222449a (diff)
module clean up
git-svn-id: https://rt-thread.googlecode.com/svn/trunk@915 bbd45198-f89e-11dd-88c7-29a3b14d5316
Diffstat (limited to 'src')
-rw-r--r--src/module.c26
-rw-r--r--src/object.c14
-rw-r--r--src/scheduler.c7
-rw-r--r--src/thread.c6
4 files changed, 30 insertions, 23 deletions
diff --git a/src/module.c b/src/module.c
index c76aafcbd3..44a0081d54 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 <rtm.h>
+
#include <rtthread.h>
+#include <rtm.h>
#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 559abf72e4..e8adc60cc2 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 be71234370..d14328feba 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 953cf9a0ca..536189070e 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 */