Skip to content

[kernel]【示例】如何给RT-Thread提交PR | beautify code #5890

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Apr 29, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
68 changes: 34 additions & 34 deletions include/rtdef.h
Original file line number Diff line number Diff line change
Expand Up @@ -387,7 +387,7 @@ struct rt_object

#ifdef RT_USING_MODULE
void *module_id; /**< id of application module */
#endif
#endif /* RT_USING_MODULE */
rt_list_t list; /**< list node of kernel object */
};
typedef struct rt_object *rt_object_t; /**< Type for kernel objects. */
Expand Down Expand Up @@ -450,8 +450,8 @@ struct rt_object_information
#define __ON_HOOK_ARGS(__hook, argv) do {if ((__hook) != RT_NULL) __hook argv; } while (0)
#else
#define __ON_HOOK_ARGS(__hook, argv)
#endif
#endif
#endif /* RT_HOOK_USING_FUNC_PTR */
#endif /* RT_USING_HOOK */

#ifndef __on_rt_interrupt_switch_hook
#define __on_rt_interrupt_switch_hook() __ON_HOOK_ARGS(rt_interrupt_switch_hook, ())
Expand Down Expand Up @@ -528,7 +528,7 @@ typedef void (*rt_sighandler_t)(int signo);
typedef siginfo_t rt_siginfo_t;

#define RT_SIG_MAX 32
#endif
#endif /* RT_USING_SIGNALS */
/**@}*/

/**
Expand Down Expand Up @@ -576,11 +576,11 @@ typedef siginfo_t rt_siginfo_t;

#ifndef RT_SCHEDULE_IPI
#define RT_SCHEDULE_IPI 0
#endif
#endif /* RT_SCHEDULE_IPI */

#ifndef RT_STOP_IPI
#define RT_STOP_IPI 1
#endif
#endif /* RT_STOP_IPI */

/**
* CPUs definitions
Expand All @@ -600,12 +600,12 @@ struct rt_cpu
rt_uint8_t ready_table[32];
#else
rt_uint32_t priority_group;
#endif
#endif /* RT_THREAD_PRIORITY_MAX > 32 */

rt_tick_t tick;
};

#endif
#endif /* RT_USING_SMP */

/**
* Thread structure
Expand All @@ -619,7 +619,7 @@ struct rt_thread

#ifdef RT_USING_MODULE
void *module_id; /**< id of application module */
#endif
#endif /* RT_USING_MODULE */

rt_list_t list; /**< the object list */
rt_list_t tlist; /**< the thread list */
Expand Down Expand Up @@ -650,32 +650,32 @@ struct rt_thread
#if RT_THREAD_PRIORITY_MAX > 32
rt_uint8_t number;
rt_uint8_t high_mask;
#endif
#endif /* RT_THREAD_PRIORITY_MAX > 32 */
rt_uint32_t number_mask;

#if defined(RT_USING_EVENT)
#ifdef RT_USING_EVENT
/* thread event */
rt_uint32_t event_set;
rt_uint8_t event_info;
#endif
#endif /* RT_USING_EVENT */

#if defined(RT_USING_SIGNALS)
#ifdef RT_USING_SIGNALS
rt_sigset_t sig_pending; /**< the pending signals */
rt_sigset_t sig_mask; /**< the mask bits of signal */

#ifndef RT_USING_SMP
void *sig_ret; /**< the return stack pointer from signal */
#endif
#endif /* RT_USING_SMP */
rt_sighandler_t *sig_vectors; /**< vectors of signal handler */
void *si_list; /**< the signal infor list */
#endif
#endif /* RT_USING_SIGNALS */

rt_ubase_t init_tick; /**< thread's initialized tick */
rt_ubase_t remaining_tick; /**< remaining tick */

#ifdef RT_USING_CPU_USAGE
rt_uint64_t duration_tick; /**< cpu usage tick */
#endif
#endif /* RT_USING_CPU_USAGE */

struct rt_timer thread_timer; /**< built-in thread timer */

Expand All @@ -684,7 +684,7 @@ struct rt_thread
/* light weight process if present */
#ifdef RT_USING_LWP
void *lwp;
#endif
#endif /* RT_USING_LWP */

rt_ubase_t user_data; /**< private user data beyond this thread */
};
Expand Down Expand Up @@ -732,7 +732,7 @@ struct rt_semaphore
rt_uint16_t reserved; /**< reserved field */
};
typedef struct rt_semaphore *rt_sem_t;
#endif
#endif /* RT_USING_SEMAPHORE */

#ifdef RT_USING_MUTEX
/**
Expand All @@ -750,7 +750,7 @@ struct rt_mutex
struct rt_thread *owner; /**< current owner of mutex */
};
typedef struct rt_mutex *rt_mutex_t;
#endif
#endif /* RT_USING_MUTEX */

#ifdef RT_USING_EVENT
/**
Expand All @@ -770,7 +770,7 @@ struct rt_event
rt_uint32_t set; /**< event set */
};
typedef struct rt_event *rt_event_t;
#endif
#endif /* RT_USING_EVENT */

#ifdef RT_USING_MAILBOX
/**
Expand All @@ -791,7 +791,7 @@ struct rt_mailbox
rt_list_t suspend_sender_thread; /**< sender thread suspended on this mailbox */
};
typedef struct rt_mailbox *rt_mailbox_t;
#endif
#endif /* RT_USING_MAILBOX */

#ifdef RT_USING_MESSAGEQUEUE
/**
Expand All @@ -815,7 +815,7 @@ struct rt_messagequeue
rt_list_t suspend_sender_thread; /**< sender thread suspended on this message queue */
};
typedef struct rt_messagequeue *rt_mq_t;
#endif
#endif /* RT_USING_MESSAGEQUEUE */

/**@}*/

Expand All @@ -839,7 +839,7 @@ struct rt_memory
rt_size_t max; /**< maximum usage */
};
typedef struct rt_memory *rt_mem_t;
#endif
#endif /* RT_USING_HEAP */

/*
* memory management
Expand All @@ -848,11 +848,11 @@ typedef struct rt_memory *rt_mem_t;

#ifdef RT_USING_SMALL_MEM
typedef rt_mem_t rt_smem_t;
#endif
#endif /* RT_USING_SMALL_MEM */

#ifdef RT_USING_SLAB
typedef rt_mem_t rt_slab_t;
#endif
#endif /* RT_USING_SLAB */

#ifdef RT_USING_MEMHEAP
/**
Expand All @@ -870,7 +870,7 @@ struct rt_memheap_item
struct rt_memheap_item *prev_free; /**< prev free memheap item */
#ifdef RT_USING_MEMTRACE
rt_uint8_t owner_thread_name[4]; /**< owner thread name */
#endif
#endif /* RT_USING_MEMTRACE */
};

/**
Expand All @@ -894,7 +894,7 @@ struct rt_memheap
struct rt_semaphore lock; /**< semaphore lock */
rt_bool_t locked; /**< External lock mark */
};
#endif
#endif /* RT_USING_MEMHEAP */

#ifdef RT_USING_MEMPOOL
/**
Expand All @@ -916,7 +916,7 @@ struct rt_mempool
rt_list_t suspend_thread; /**< threads pended on this resource */
};
typedef struct rt_mempool *rt_mp_t;
#endif
#endif /* RT_USING_MEMPOOL */

/**@}*/

Expand Down Expand Up @@ -1036,7 +1036,7 @@ struct rt_device_ops
rt_size_t (*write) (rt_device_t dev, rt_off_t pos, const void *buffer, rt_size_t size);
rt_err_t (*control)(rt_device_t dev, int cmd, void *args);
};
#endif
#endif /* RT_USING_DEVICE_OPS */

/**
* WaitQueue structure
Expand Down Expand Up @@ -1076,12 +1076,12 @@ struct rt_device
rt_size_t (*read) (rt_device_t dev, rt_off_t pos, void *buffer, rt_size_t size);
rt_size_t (*write) (rt_device_t dev, rt_off_t pos, const void *buffer, rt_size_t size);
rt_err_t (*control)(rt_device_t dev, int cmd, void *args);
#endif
#endif /* RT_USING_DEVICE_OPS */

#ifdef RT_USING_POSIX_DEVIO
const struct dfs_file_ops *fops;
struct rt_wqueue wait_queue;
#endif
#endif /* RT_USING_POSIX_DEVIO */

void *user_data; /**< device private data */
};
Expand Down Expand Up @@ -1194,7 +1194,7 @@ struct rt_device_graphic_ops
#define rt_graphix_ops(device) ((struct rt_device_graphic_ops *)(device->user_data))

/**@}*/
#endif
#endif /* RT_USING_DEVICE */

#ifdef __cplusplus
}
Expand All @@ -1211,6 +1211,6 @@ enum TICK_WAIT {

}

#endif /* end of __cplusplus */
#endif /* __cplusplus */

#endif
#endif /* __RT_DEF_H__ */
24 changes: 11 additions & 13 deletions src/thread.c
Original file line number Diff line number Diff line change
Expand Up @@ -85,8 +85,7 @@ void rt_thread_inited_sethook(void (*hook)(rt_thread_t thread))
{
rt_thread_inited_hook = hook;
}

#endif /* RT_USING_HOOK */
#endif /* defined(RT_USING_HOOK) && defined(RT_HOOK_USING_FUNC_PTR) */

static void _thread_exit(void)
{
Expand Down Expand Up @@ -195,7 +194,7 @@ static rt_err_t _thread_init(struct rt_thread *thread,
#ifdef RT_USING_EVENT
thread->event_set = 0;
thread->event_info = 0;
#endif
#endif /* RT_USING_EVENT */

#if RT_THREAD_PRIORITY_MAX > 32
thread->number = 0;
Expand Down Expand Up @@ -251,12 +250,11 @@ static rt_err_t _thread_init(struct rt_thread *thread,

#ifdef RT_USING_CPU_USAGE
thread->duration_tick = 0;
#endif

#endif /* RT_USING_CPU_USAGE */

#ifdef RT_USING_MODULE
thread->module_id = 0;
#endif
#endif /* RT_USING_MODULE */

RT_OBJECT_HOOK_CALL(rt_thread_inited_hook, (thread));

Expand Down Expand Up @@ -473,13 +471,13 @@ rt_thread_t rt_thread_create(const char *name,
}

_thread_init(thread,
name,
entry,
parameter,
stack_start,
stack_size,
priority,
tick);
name,
entry,
parameter,
stack_start,
stack_size,
priority,
tick);

return thread;
}
Expand Down
8 changes: 4 additions & 4 deletions src/timer.c
Original file line number Diff line number Diff line change
Expand Up @@ -118,10 +118,10 @@ void rt_timer_exit_sethook(void (*hook)(struct rt_timer *timer))
* @param flag the flag of timer
*/
static void _timer_init(rt_timer_t timer,
void (*timeout)(void *parameter),
void *parameter,
rt_tick_t time,
rt_uint8_t flag)
void (*timeout)(void *parameter),
void *parameter,
rt_tick_t time,
rt_uint8_t flag)
{
int i;

Expand Down