summaryrefslogtreecommitdiff
path: root/src/thread.c
diff options
context:
space:
mode:
Diffstat (limited to 'src/thread.c')
-rw-r--r--src/thread.c99
1 files changed, 49 insertions, 50 deletions
diff --git a/src/thread.c b/src/thread.c
index f7f0bffafe..92ea9d4595 100644
--- a/src/thread.c
+++ b/src/thread.c
@@ -1,7 +1,7 @@
/*
* File : thread.c
* This file is part of RT-Thread RTOS
- * COPYRIGHT (C) 2006 - 2010, RT-Thread Development Team
+ * COPYRIGHT (C) 2006 - 2011, RT-Thread Development Team
*
* The license and distribution terms for this file may be
* found in the file LICENSE in this distribution or at
@@ -29,25 +29,24 @@
#include <rthw.h>
#include "kservice.h"
-
extern rt_list_t rt_thread_priority_table[RT_THREAD_PRIORITY_MAX];
-extern struct rt_thread* rt_current_thread;
+extern struct rt_thread *rt_current_thread;
extern rt_uint8_t rt_current_priority;
extern rt_list_t rt_thread_defunct;
static void rt_thread_exit(void);
-void rt_thread_timeout(void* parameter);
+void rt_thread_timeout(void *parameter);
-static rt_err_t _rt_thread_init(struct rt_thread* thread,
- const char* name,
- void (*entry)(void* parameter), void* parameter,
- void* stack_start, rt_uint32_t stack_size,
+static rt_err_t _rt_thread_init(struct rt_thread *thread,
+ const char *name,
+ void (*entry)(void *parameter), void *parameter,
+ void *stack_start, rt_uint32_t stack_size,
rt_uint8_t priority, rt_uint32_t tick)
{
/* init thread list */
rt_list_init(&(thread->tlist));
- thread->entry = (void*)entry;
+ thread->entry = (void *)entry;
thread->parameter = parameter;
/* stack init */
@@ -56,9 +55,9 @@ static rt_err_t _rt_thread_init(struct rt_thread* thread,
/* init thread stack */
rt_memset(thread->stack_addr, '#', thread->stack_size);
- thread->sp = (void*)rt_hw_stack_init(thread->entry, thread->parameter,
+ thread->sp = (void *)rt_hw_stack_init(thread->entry, thread->parameter,
(void *) ((char *)thread->stack_addr + thread->stack_size - 4),
- (void*)rt_thread_exit);
+ (void *)rt_thread_exit);
/* priority init */
RT_ASSERT(priority < RT_THREAD_PRIORITY_MAX);
@@ -110,10 +109,10 @@ static rt_err_t _rt_thread_init(struct rt_thread* thread,
* @return the operation status, RT_EOK on OK, -RT_ERROR on error
*
*/
-rt_err_t rt_thread_init(struct rt_thread* thread,
- const char* name,
- void (*entry)(void* parameter), void* parameter,
- void* stack_start, rt_uint32_t stack_size,
+rt_err_t rt_thread_init(struct rt_thread *thread,
+ const char *name,
+ void (*entry)(void *parameter), void *parameter,
+ void *stack_start, rt_uint32_t stack_size,
rt_uint8_t priority, rt_uint32_t tick)
{
/* thread check */
@@ -143,19 +142,19 @@ rt_err_t rt_thread_init(struct rt_thread* thread,
* @return the created thread object
*
*/
-rt_thread_t rt_thread_create (const char* name,
- void (*entry)(void* parameter), void* parameter,
+rt_thread_t rt_thread_create (const char *name,
+ void (*entry)(void *parameter), void *parameter,
rt_uint32_t stack_size,
rt_uint8_t priority,
rt_uint32_t tick)
{
- struct rt_thread* thread;
- void* stack_start;
+ struct rt_thread *thread;
+ void *stack_start;
- thread = (struct rt_thread*) rt_object_allocate(RT_Object_Class_Thread, name);
+ thread = (struct rt_thread *) rt_object_allocate(RT_Object_Class_Thread, name);
if (thread == RT_NULL) return RT_NULL;
- stack_start = (void*)rt_malloc(stack_size);
+ stack_start = (void *)rt_malloc(stack_size);
if (stack_start == RT_NULL)
{
/* allocate stack failure */
@@ -177,7 +176,7 @@ rt_thread_t rt_thread_create (const char* name,
* @return the self thread object
*
*/
-rt_thread_t rt_thread_self (void)
+rt_thread_t rt_thread_self(void)
{
return rt_current_thread;
}
@@ -190,7 +189,7 @@ rt_thread_t rt_thread_self (void)
* @return the operation status, RT_EOK on OK, -RT_ERROR on error
*
*/
-rt_err_t rt_thread_startup (rt_thread_t thread)
+rt_err_t rt_thread_startup(rt_thread_t thread)
{
/* thread check */
RT_ASSERT(thread != RT_NULL);
@@ -201,11 +200,11 @@ rt_err_t rt_thread_startup (rt_thread_t thread)
/* calculate priority attribute */
#if RT_THREAD_PRIORITY_MAX > 32
- thread->number = thread->current_priority >> 3; /* 5bit */
- thread->number_mask = 1L << thread->number;
- thread->high_mask = 1L << (thread->current_priority & 0x07); /* 3bit */
+ thread->number = thread->current_priority >> 3; /* 5bit */
+ thread->number_mask = 1L << thread->number;
+ thread->high_mask = 1L << (thread->current_priority & 0x07); /* 3bit */
#else
- thread->number_mask = 1L << thread->current_priority; //1L means long int,fixed compile mistake with IAR EW M16C v3.401,fify 20100410
+ thread->number_mask = 1L << thread->current_priority;
#endif
RT_DEBUG_LOG(RT_DEBUG_THREAD,\
@@ -223,9 +222,9 @@ rt_err_t rt_thread_startup (rt_thread_t thread)
return RT_EOK;
}
-static void rt_thread_exit()
+static void rt_thread_exit(void)
{
- struct rt_thread* thread;
+ struct rt_thread *thread;
register rt_base_t level;
/* get current thread */
@@ -270,7 +269,7 @@ static void rt_thread_exit()
* @return the operation status, RT_EOK on OK, -RT_ERROR on error
*
*/
-rt_err_t rt_thread_detach (rt_thread_t thread)
+rt_err_t rt_thread_detach(rt_thread_t thread)
{
rt_base_t lock;
@@ -314,7 +313,7 @@ rt_err_t rt_thread_detach (rt_thread_t thread)
* @return the operation status, RT_EOK on OK, -RT_ERROR on error
*
*/
-rt_err_t rt_thread_delete (rt_thread_t thread)
+rt_err_t rt_thread_delete(rt_thread_t thread)
{
rt_base_t lock;
@@ -351,7 +350,7 @@ rt_err_t rt_thread_delete (rt_thread_t thread)
* @return RT_EOK
*
*/
-rt_err_t rt_thread_yield ()
+rt_err_t rt_thread_yield(void)
{
register rt_base_t level;
struct rt_thread *thread;
@@ -394,7 +393,7 @@ rt_err_t rt_thread_yield ()
* @return RT_EOK
*
*/
-rt_err_t rt_thread_sleep (rt_tick_t tick)
+rt_err_t rt_thread_sleep(rt_tick_t tick)
{
register rt_base_t temp;
struct rt_thread *thread;
@@ -449,7 +448,7 @@ rt_err_t rt_thread_delay(rt_tick_t tick)
*
* @return RT_EOK
*/
-rt_err_t rt_thread_control (rt_thread_t thread, rt_uint8_t cmd, void* arg)
+rt_err_t rt_thread_control(rt_thread_t thread, rt_uint8_t cmd, void *arg)
{
register rt_base_t temp;
@@ -469,13 +468,13 @@ rt_err_t rt_thread_control (rt_thread_t thread, rt_uint8_t cmd, void* arg)
rt_schedule_remove_thread(thread);
/* change thread priority */
- thread->current_priority = *(rt_uint8_t*) arg;
+ thread->current_priority = *(rt_uint8_t *)arg;
/* recalculate priority attribute */
#if RT_THREAD_PRIORITY_MAX > 32
- thread->number = thread->current_priority >> 3; /* 5bit */
- thread->number_mask = 1 << thread->number;
- thread->high_mask = 1 << (thread->current_priority & 0x07); /* 3bit */
+ thread->number = thread->current_priority >> 3; /* 5bit */
+ thread->number_mask = 1 << thread->number;
+ thread->high_mask = 1 << (thread->current_priority & 0x07); /* 3bit */
#else
thread->number_mask = 1 << thread->current_priority;
#endif
@@ -485,13 +484,13 @@ rt_err_t rt_thread_control (rt_thread_t thread, rt_uint8_t cmd, void* arg)
}
else
{
- thread->current_priority = *(rt_uint8_t*) arg;
+ thread->current_priority = *(rt_uint8_t *)arg;
/* recalculate priority attribute */
#if RT_THREAD_PRIORITY_MAX > 32
- thread->number = thread->current_priority >> 3; /* 5bit */
- thread->number_mask = 1 << thread->number;
- thread->high_mask = 1 << (thread->current_priority & 0x07); /* 3bit */
+ thread->number = thread->current_priority >> 3; /* 5bit */
+ thread->number_mask = 1 << thread->number;
+ thread->high_mask = 1 << (thread->current_priority & 0x07); /* 3bit */
#else
thread->number_mask = 1 << thread->current_priority;
#endif
@@ -526,7 +525,7 @@ rt_err_t rt_thread_control (rt_thread_t thread, rt_uint8_t cmd, void* arg)
* @note if suspend self thread, after this function call, the
* rt_schedule() must be invoked.
*/
-rt_err_t rt_thread_suspend (rt_thread_t thread)
+rt_err_t rt_thread_suspend(rt_thread_t thread)
{
register rt_base_t temp;
@@ -564,7 +563,7 @@ rt_err_t rt_thread_suspend (rt_thread_t thread)
* @return the operation status, RT_EOK on OK, -RT_ERROR on error
*
*/
-rt_err_t rt_thread_resume (rt_thread_t thread)
+rt_err_t rt_thread_resume(rt_thread_t thread)
{
register rt_base_t temp;
@@ -609,11 +608,11 @@ rt_err_t rt_thread_resume (rt_thread_t thread)
* @param parameter the parameter of thread timeout function
*
*/
-void rt_thread_timeout(void* parameter)
+void rt_thread_timeout(void *parameter)
{
- struct rt_thread* thread;
+ struct rt_thread *thread;
- thread = (struct rt_thread*) parameter;
+ thread = (struct rt_thread *)parameter;
/* thread check */
RT_ASSERT(thread != RT_NULL);
@@ -641,11 +640,11 @@ void rt_thread_timeout(void* parameter)
*
* @note please don't invoke this function in interrupt status.
*/
-rt_thread_t rt_thread_find(char* name)
+rt_thread_t rt_thread_find(char *name)
{
struct rt_object_information *information;
- struct rt_object* object;
- struct rt_list_node* node;
+ struct rt_object *object;
+ struct rt_list_node *node;
extern struct rt_object_information rt_object_container[];