mirror of
https://github.com/RT-Thread/rt-thread.git
synced 2025-11-16 12:34:33 +00:00
implement module memory allocator
git-svn-id: https://rt-thread.googlecode.com/svn/trunk@1030 bbd45198-f89e-11dd-88c7-29a3b14d5316
This commit is contained in:
@@ -10,7 +10,8 @@
|
||||
* Change Logs:
|
||||
* Date Author Notes
|
||||
* 2007-01-10 Bernard the first version
|
||||
* 2008-07-12 Bernard remove all rt_int8, rt_uint32_t etc typedef
|
||||
* 2008-07-12 Bernard remove all rt_int8, rt_uint32_t etc typedef
|
||||
* 2010-10-26 yi.qiu add module support
|
||||
*/
|
||||
#ifndef __RT_DEF_H__
|
||||
#define __RT_DEF_H__
|
||||
@@ -163,6 +164,12 @@ typedef struct rt_list_node rt_list_t; /* Type for lists. */
|
||||
* @addtogroup KernelObject
|
||||
*/
|
||||
/*@{*/
|
||||
|
||||
/*
|
||||
* kernel object macros
|
||||
*/
|
||||
#define RT_OBJECT_FLAG_MODULE 0x80 /* is module object. */
|
||||
|
||||
/*
|
||||
* Base structure of Kernel object
|
||||
*/
|
||||
@@ -174,6 +181,12 @@ struct rt_object
|
||||
rt_uint8_t type;
|
||||
/* flag of kernel object */
|
||||
rt_uint8_t flag;
|
||||
|
||||
#ifdef RT_USING_MODULE
|
||||
/* id of application module */
|
||||
void* module_id;
|
||||
#endif
|
||||
|
||||
/* list pointer of kernel object */
|
||||
rt_list_t list;
|
||||
};
|
||||
@@ -303,7 +316,6 @@ typedef struct rt_timer* rt_timer_t;
|
||||
#define RT_THREAD_CTRL_INFO 0x03 /* Get thread information. */
|
||||
|
||||
typedef struct rt_thread* rt_thread_t;
|
||||
typedef struct rt_module* rt_module_t;
|
||||
|
||||
/*
|
||||
* Thread related structure
|
||||
@@ -314,6 +326,10 @@ struct rt_thread
|
||||
char name[RT_NAME_MAX]; /* the name of thread */
|
||||
rt_uint8_t type; /* type of object */
|
||||
rt_uint8_t flags; /* thread's flags */
|
||||
|
||||
#ifdef RT_USING_MODULE
|
||||
void* module_id; /* id of application module */
|
||||
#endif
|
||||
|
||||
rt_list_t list; /* the object list */
|
||||
rt_list_t tlist; /* the thread list */
|
||||
@@ -350,10 +366,6 @@ struct rt_thread
|
||||
|
||||
struct rt_timer thread_timer; /* thread timer */
|
||||
|
||||
#ifdef RT_USING_MODULE
|
||||
rt_module_t module_parent; /* module parent */
|
||||
#endif
|
||||
|
||||
rt_uint32_t user_data; /* user data */
|
||||
};
|
||||
/*@}*/
|
||||
@@ -362,33 +374,26 @@ struct rt_thread
|
||||
/*
|
||||
* module system
|
||||
*/
|
||||
enum rt_module_class_type
|
||||
{
|
||||
RT_Module_Class_APP = 0, /* application module */
|
||||
RT_Module_Class_EXTENSION,
|
||||
RT_Module_Class_SERVICE, /* service module */
|
||||
RT_Module_Class_Unknown /* unknown module */
|
||||
};
|
||||
|
||||
struct rt_module
|
||||
{
|
||||
/* inherit from object */
|
||||
struct rt_object parent;
|
||||
struct rt_object parent;
|
||||
|
||||
rt_uint8_t* module_space;
|
||||
rt_uint8_t* module_space; /* module memory space */
|
||||
|
||||
void* module_entry;
|
||||
rt_uint32_t stack_size;
|
||||
void* module_entry; /* entry address of module's thread */
|
||||
rt_thread_t module_thread; /* stack size of module's thread */
|
||||
rt_uint32_t stack_size; /* priority of module's thread */
|
||||
rt_uint32_t thread_priority;
|
||||
rt_thread_t module_thread;
|
||||
|
||||
/* module memory pool */
|
||||
rt_uint32_t mempool_size;
|
||||
void* module_mempool;
|
||||
/* module memory allocator */
|
||||
void* module_mem_list;
|
||||
rt_list_t module_page;
|
||||
|
||||
/* object in this module, module object is the last basic object type */
|
||||
struct rt_object_information module_object[RT_Object_Class_Module];
|
||||
};
|
||||
typedef struct rt_module* rt_module_t;
|
||||
#endif
|
||||
|
||||
/**
|
||||
|
||||
@@ -14,7 +14,7 @@
|
||||
* 2006-08-10 Bernard add version information
|
||||
* 2007-01-28 Bernard rename RT_OBJECT_Class_Static to RT_Object_Class_Static
|
||||
* 2007-03-03 Bernard clean up the definitions to rtdef.h
|
||||
* 2010-04-11 yi.qiu add module feature
|
||||
* 2010-04-11 yi.qiu add module feature
|
||||
*/
|
||||
|
||||
#ifndef __RT_THREAD_H__
|
||||
@@ -184,6 +184,11 @@ void rt_memory_info(rt_uint32_t *total,
|
||||
void rt_malloc_sethook(void (*hook)(void *ptr, rt_uint32_t size));
|
||||
void rt_free_sethook(void (*hook)(void *ptr));
|
||||
#endif
|
||||
|
||||
#ifdef RT_USING_SLAB
|
||||
void *rt_page_alloc(rt_size_t npages);
|
||||
void rt_page_free(void *addr, rt_size_t npages);
|
||||
#endif
|
||||
#endif
|
||||
/*@}*/
|
||||
|
||||
@@ -305,8 +310,11 @@ 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_module_t rt_module_load_from_file(const rt_uint8_t* name, const char* filename);
|
||||
rt_err_t rt_module_unload(rt_module_t module);
|
||||
rt_err_t rt_module_self_set (rt_module_t module);
|
||||
void *rt_module_malloc(rt_size_t size);
|
||||
void *rt_module_realloc(void *ptr, rt_size_t size);
|
||||
void rt_module_free(rt_module_t module, void *addr);
|
||||
rt_module_t rt_module_self (void);
|
||||
rt_err_t rt_module_set (rt_module_t module);
|
||||
rt_module_t rt_module_find(char* name);
|
||||
#endif
|
||||
|
||||
@@ -343,6 +351,7 @@ void* rt_memset(void *src, int c, rt_ubase_t n);
|
||||
void* rt_memcpy(void *dest, const void *src, rt_ubase_t n);
|
||||
|
||||
rt_ubase_t rt_strncmp(const char * cs, const char * ct, rt_ubase_t count);
|
||||
rt_ubase_t rt_strcmp (const char *cs, const char *ct);
|
||||
rt_ubase_t rt_strlen (const char *src);
|
||||
char *rt_strdup(const char *s);
|
||||
|
||||
|
||||
Reference in New Issue
Block a user