From fb7d4122fc97be364cf2ce76380b0e5465aba7eb Mon Sep 17 00:00:00 2001 From: qiuyiuestc Date: Thu, 28 Oct 2010 01:21:47 +0000 Subject: implement module memory allocator git-svn-id: https://rt-thread.googlecode.com/svn/trunk@1030 bbd45198-f89e-11dd-88c7-29a3b14d5316 --- src/object.c | 20 +++++++++++++++++++- 1 file changed, 19 insertions(+), 1 deletion(-) (limited to 'src/object.c') diff --git a/src/object.c b/src/object.c index 2b8ccb62d3..c992f0fe04 100644 --- a/src/object.c +++ b/src/object.c @@ -14,6 +14,7 @@ * 2006-05-18 Bernard fix the object init bug * 2006-08-03 Bernard add hook support * 2007-01-28 Bernard rename RT_OBJECT_Class_Static to RT_Object_Class_Static + * 2010-10-26 yi.qiu add module support in rt_object_allocate and rt_object_free */ #include @@ -270,12 +271,23 @@ rt_object_t rt_object_allocate(enum rt_object_class_type type, const char* name) /* no memory can be allocated */ return RT_NULL; } - + /* init object's parameters */ /* set object type */ object->type = type; + /* set object flag */ + object->flag = 0; + +#ifdef RT_USING_MODULE + if(rt_module_self() != RT_NULL) + { + object->module_id = (void*)rt_module_self(); + object->flag |= RT_OBJECT_FLAG_MODULE; + } +#endif + /* copy name */ for (temp = 0; temp < RT_NAME_MAX; temp ++) { @@ -325,6 +337,12 @@ void rt_object_delete(rt_object_t object) /* unlock interrupt */ rt_hw_interrupt_enable(temp); +#ifdef RT_USING_MODULE + if(object->flag & RT_OBJECT_FLAG_MODULE) + rt_module_free((rt_module_t)object->module_id, object); + else +#endif + /* free the memory of object */ rt_free(object); } -- cgit v1.3.1