Skip to content

Commit 8e31120

Browse files
authored
Merge pull request #5038 from liukangcc/annotation
[update] src/thread.c function description.
2 parents a8fd81f + 202b233 commit 8e31120

File tree

1 file changed

+119
-88
lines changed

1 file changed

+119
-88
lines changed

src/thread.c

Lines changed: 119 additions & 88 deletions
Original file line numberDiff line numberDiff line change
@@ -38,36 +38,33 @@ static void (*rt_thread_resume_hook) (rt_thread_t thread);
3838
static void (*rt_thread_inited_hook) (rt_thread_t thread);
3939

4040
/**
41-
* @ingroup Hook
42-
* This function sets a hook function when the system suspend a thread.
41+
* @brief This function sets a hook function when the system suspend a thread.
4342
*
44-
* @param hook the specified hook function
43+
* @note The hook function must be simple and never be blocked or suspend.
4544
*
46-
* @note the hook function must be simple and never be blocked or suspend.
45+
* @param hook is the specified hook function.
4746
*/
4847
void rt_thread_suspend_sethook(void (*hook)(rt_thread_t thread))
4948
{
5049
rt_thread_suspend_hook = hook;
5150
}
5251

5352
/**
54-
* @ingroup Hook
55-
* This function sets a hook function when the system resume a thread.
53+
* @brief This function sets a hook function when the system resume a thread.
5654
*
57-
* @param hook the specified hook function
55+
* @note The hook function must be simple and never be blocked or suspend.
5856
*
59-
* @note the hook function must be simple and never be blocked or suspend.
57+
* @param hook is the specified hook function.
6058
*/
6159
void rt_thread_resume_sethook(void (*hook)(rt_thread_t thread))
6260
{
6361
rt_thread_resume_hook = hook;
6462
}
6563

6664
/**
67-
* @ingroup Hook
68-
* This function sets a hook function when a thread is initialized.
65+
* @brief This function sets a hook function when a thread is initialized.
6966
*
70-
* @param hook the specified hook function
67+
* @param hook is the specified hook function.
7168
*/
7269
void rt_thread_inited_sethook(void (*hook)(rt_thread_t thread))
7370
{
@@ -76,7 +73,6 @@ void rt_thread_inited_sethook(void (*hook)(rt_thread_t thread))
7673

7774
#endif /* RT_USING_HOOK */
7875

79-
/* must be invoke witch rt_hw_interrupt_disable */
8076
static void _thread_cleanup_execute(rt_thread_t thread)
8177
{
8278
register rt_base_t level;
@@ -244,19 +240,27 @@ static rt_err_t _thread_init(struct rt_thread *thread,
244240
/**@{*/
245241

246242
/**
247-
* This function will initialize a thread, normally it's used to initialize a
248-
* static thread object.
249-
*
250-
* @param thread the static thread object
251-
* @param name the name of thread, which shall be unique
252-
* @param entry the entry function of thread
253-
* @param parameter the parameter of thread enter function
254-
* @param stack_start the start address of thread stack
255-
* @param stack_size the size of thread stack
256-
* @param priority the priority of thread
257-
* @param tick the time slice if there are same priority thread
258-
*
259-
* @return the operation status, RT_EOK on OK, -RT_ERROR on error
243+
* @brief This function will initialize a thread. It's used to initialize a
244+
* static thread object.
245+
*
246+
* @param thread is the static thread object.
247+
*
248+
* @param name is the name of thread, which shall be unique.
249+
*
250+
* @param entry is the entry function of thread.
251+
*
252+
* @param parameter is the parameter of thread enter function.
253+
*
254+
* @param stack_start is the start address of thread stack.
255+
*
256+
* @param stack_size is the size of thread stack.
257+
*
258+
* @param priority is the priority of thread.
259+
*
260+
* @param tick is the time slice if there are same priority thread.
261+
*
262+
* @return Return the operation status. If the return value is RT_EOK, the function is successfully executed.
263+
* If the return value is any other values, it means this operation failed.
260264
*/
261265
rt_err_t rt_thread_init(struct rt_thread *thread,
262266
const char *name,
@@ -286,9 +290,9 @@ rt_err_t rt_thread_init(struct rt_thread *thread,
286290
RTM_EXPORT(rt_thread_init);
287291

288292
/**
289-
* This function will return self thread object
293+
* @brief This function will return self thread object.
290294
*
291-
* @return the self thread object
295+
* @return The self thread object.
292296
*/
293297
rt_thread_t rt_thread_self(void)
294298
{
@@ -309,11 +313,12 @@ rt_thread_t rt_thread_self(void)
309313
RTM_EXPORT(rt_thread_self);
310314

311315
/**
312-
* This function will start a thread and put it to system ready queue
316+
* @brief This function will start a thread and put it to system ready queue.
313317
*
314-
* @param thread the thread to be started
318+
* @param thread is the thread to be started.
315319
*
316-
* @return the operation status, RT_EOK on OK, -RT_ERROR on error
320+
* @return Return the operation status. If the return value is RT_EOK, the function is successfully executed.
321+
* If the return value is any other values, it means this operation failed.
317322
*/
318323
rt_err_t rt_thread_startup(rt_thread_t thread)
319324
{
@@ -351,12 +356,13 @@ rt_err_t rt_thread_startup(rt_thread_t thread)
351356
RTM_EXPORT(rt_thread_startup);
352357

353358
/**
354-
* This function will detach a thread. The thread object will be removed from
355-
* thread queue and detached/deleted from system object management.
359+
* @brief This function will detach a thread. The thread object will be removed from
360+
* thread queue and detached/deleted from the system object management.
356361
*
357-
* @param thread the thread to be deleted
362+
* @param thread is the thread to be deleted.
358363
*
359-
* @return the operation status, RT_EOK on OK, -RT_ERROR on error
364+
* @return Return the operation status. If the return value is RT_EOK, the function is successfully executed.
365+
* If the return value is any other values, it means this operation failed.
360366
*/
361367
rt_err_t rt_thread_detach(rt_thread_t thread)
362368
{
@@ -404,17 +410,23 @@ RTM_EXPORT(rt_thread_detach);
404410

405411
#ifdef RT_USING_HEAP
406412
/**
407-
* This function will create a thread object and allocate thread object memory
408-
* and stack.
413+
* @brief This function will create a thread object and allocate thread object memory.
414+
* and stack.
415+
*
416+
* @param name is the name of thread, which shall be unique.
417+
*
418+
* @param entry is the entry function of thread.
409419
*
410-
* @param name the name of thread, which shall be unique
411-
* @param entry the entry function of thread
412-
* @param parameter the parameter of thread enter function
413-
* @param stack_size the size of thread stack
414-
* @param priority the priority of thread
415-
* @param tick the time slice if there are same priority thread
420+
* @param parameter is the parameter of thread enter function.
416421
*
417-
* @return the created thread object
422+
* @param stack_size is the size of thread stack.
423+
*
424+
* @param priority is the priority of thread.
425+
*
426+
* @param tick is the time slice if there are same priority thread.
427+
*
428+
* @return If the return value is a rt_thread structure pointer, the function is successfully executed.
429+
* If the return value is RT_NULL, it means this operation failed.
418430
*/
419431
rt_thread_t rt_thread_create(const char *name,
420432
void (*entry)(void *parameter),
@@ -454,12 +466,13 @@ rt_thread_t rt_thread_create(const char *name,
454466
RTM_EXPORT(rt_thread_create);
455467

456468
/**
457-
* This function will delete a thread. The thread object will be removed from
458-
* thread queue and deleted from system object management in the idle thread.
469+
* @brief This function will delete a thread. The thread object will be removed from
470+
* thread queue and deleted from system object management in the idle thread.
459471
*
460-
* @param thread the thread to be deleted
472+
* @param thread is the thread to be deleted.
461473
*
462-
* @return the operation status, RT_EOK on OK, -RT_ERROR on error
474+
* @return Return the operation status. If the return value is RT_EOK, the function is successfully executed.
475+
* If the return value is any other values, it means this operation failed.
463476
*/
464477
rt_err_t rt_thread_delete(rt_thread_t thread)
465478
{
@@ -502,11 +515,12 @@ RTM_EXPORT(rt_thread_delete);
502515
#endif /* RT_USING_HEAP */
503516

504517
/**
505-
* This function will let current thread yield processor, and scheduler will
506-
* choose a highest thread to run. After yield processor, the current thread
507-
* is still in READY state.
518+
* @brief This function will let current thread yield processor, and scheduler will
519+
* choose the highest thread to run. After yield processor, the current thread
520+
* is still in READY state.
508521
*
509-
* @return RT_EOK
522+
* @return Return the operation status. If the return value is RT_EOK, the function is successfully executed.
523+
* If the return value is any other values, it means this operation failed.
510524
*/
511525
rt_err_t rt_thread_yield(void)
512526
{
@@ -525,11 +539,13 @@ rt_err_t rt_thread_yield(void)
525539
RTM_EXPORT(rt_thread_yield);
526540

527541
/**
528-
* This function will let current thread sleep for some ticks.
542+
* @brief This function will let current thread sleep for some ticks. Change current thread state to suspend,
543+
* when the thread timer reaches the tick value, scheduler will awaken this thread.
529544
*
530-
* @param tick the sleep ticks
545+
* @param tick is the sleep ticks.
531546
*
532-
* @return RT_EOK
547+
* @return Return the operation status. If the return value is RT_EOK, the function is successfully executed.
548+
* If the return value is any other values, it means this operation failed.
533549
*/
534550
rt_err_t rt_thread_sleep(rt_tick_t tick)
535551
{
@@ -564,11 +580,12 @@ rt_err_t rt_thread_sleep(rt_tick_t tick)
564580
}
565581

566582
/**
567-
* This function will let current thread delay for some ticks.
583+
* @brief This function will let current thread delay for some ticks.
568584
*
569-
* @param tick the delay ticks
585+
* @param tick is the delay ticks.
570586
*
571-
* @return RT_EOK
587+
* @return Return the operation status. If the return value is RT_EOK, the function is successfully executed.
588+
* If the return value is any other values, it means this operation failed.
572589
*/
573590
rt_err_t rt_thread_delay(rt_tick_t tick)
574591
{
@@ -577,12 +594,14 @@ rt_err_t rt_thread_delay(rt_tick_t tick)
577594
RTM_EXPORT(rt_thread_delay);
578595

579596
/**
580-
* This function will let current thread delay until (*tick + inc_tick).
597+
* @brief This function will let current thread delay until (*tick + inc_tick).
581598
*
582-
* @param tick the tick of last wakeup.
583-
* @param inc_tick the increment tick
599+
* @param tick is the tick of last wakeup.
584600
*
585-
* @return RT_EOK
601+
* @param inc_tick is the increment tick.
602+
*
603+
* @return Return the operation status. If the return value is RT_EOK, the function is successfully executed.
604+
* If the return value is any other values, it means this operation failed.
586605
*/
587606
rt_err_t rt_thread_delay_until(rt_tick_t *tick, rt_tick_t inc_tick)
588607
{
@@ -637,11 +656,12 @@ rt_err_t rt_thread_delay_until(rt_tick_t *tick, rt_tick_t inc_tick)
637656
RTM_EXPORT(rt_thread_delay_until);
638657

639658
/**
640-
* This function will let current thread delay for some milliseconds.
659+
* @brief This function will let current thread delay for some milliseconds.
641660
*
642-
* @param ms the delay ms time
661+
* @param ms is the delay ms time.
643662
*
644-
* @return RT_EOK
663+
* @return Return the operation status. If the return value is RT_EOK, the function is successfully executed.
664+
* If the return value is any other values, it means this operation failed.
645665
*/
646666
rt_err_t rt_thread_mdelay(rt_int32_t ms)
647667
{
@@ -654,17 +674,24 @@ rt_err_t rt_thread_mdelay(rt_int32_t ms)
654674
RTM_EXPORT(rt_thread_mdelay);
655675

656676
/**
657-
* This function will control thread behaviors according to control command.
677+
* @brief This function will control thread behaviors according to control command.
678+
*
679+
* @param thread is the specified thread to be controlled.
680+
*
681+
* @param cmd is the control command, which includes.
658682
*
659-
* @param thread the specified thread to be controlled
660-
* @param cmd the control command, which includes
661-
* RT_THREAD_CTRL_CHANGE_PRIORITY for changing priority level of thread;
662-
* RT_THREAD_CTRL_STARTUP for starting a thread;
663-
* RT_THREAD_CTRL_CLOSE for delete a thread;
664-
* RT_THREAD_CTRL_BIND_CPU for bind the thread to a CPU.
665-
* @param arg the argument of control command
683+
* RT_THREAD_CTRL_CHANGE_PRIORITY for changing priority level of thread.
666684
*
667-
* @return RT_EOK
685+
* RT_THREAD_CTRL_STARTUP for starting a thread.
686+
*
687+
* RT_THREAD_CTRL_CLOSE for delete a thread.
688+
*
689+
* RT_THREAD_CTRL_BIND_CPU for bind the thread to a CPU.
690+
*
691+
* @param arg is the argument of control command.
692+
*
693+
* @return Return the operation status. If the return value is RT_EOK, the function is successfully executed.
694+
* If the return value is any other values, it means this operation failed.
668695
*/
669696
rt_err_t rt_thread_control(rt_thread_t thread, int cmd, void *arg)
670697
{
@@ -770,14 +797,15 @@ rt_err_t rt_thread_control(rt_thread_t thread, int cmd, void *arg)
770797
RTM_EXPORT(rt_thread_control);
771798

772799
/**
773-
* This function will suspend the specified thread.
800+
* @brief This function will suspend the specified thread and change it to suspend state.
774801
*
775-
* @param thread the thread to be suspended
802+
* @note If suspend self thread, after this function call, the
803+
* rt_schedule() must be invoked.
776804
*
777-
* @return the operation status, RT_EOK on OK, -RT_ERROR on error
805+
* @param thread is the thread to be suspended.
778806
*
779-
* @note if suspend self thread, after this function call, the
780-
* rt_schedule() must be invoked.
807+
* @return Return the operation status. If the return value is RT_EOK, the function is successfully executed.
808+
* If the return value is any other values, it means this operation failed.
781809
*/
782810
rt_err_t rt_thread_suspend(rt_thread_t thread)
783811
{
@@ -822,11 +850,12 @@ rt_err_t rt_thread_suspend(rt_thread_t thread)
822850
RTM_EXPORT(rt_thread_suspend);
823851

824852
/**
825-
* This function will resume a thread and put it to system ready queue.
853+
* @brief This function will resume a thread and put it to system ready queue.
826854
*
827-
* @param thread the thread to be resumed
855+
* @param thread is the thread to be resumed.
828856
*
829-
* @return the operation status, RT_EOK on OK, -RT_ERROR on error
857+
* @return Return the operation status. If the return value is RT_EOK, the function is successfully executed.
858+
* If the return value is any other values, it means this operation failed.
830859
*/
831860
rt_err_t rt_thread_resume(rt_thread_t thread)
832861
{
@@ -866,10 +895,10 @@ rt_err_t rt_thread_resume(rt_thread_t thread)
866895
RTM_EXPORT(rt_thread_resume);
867896

868897
/**
869-
* This function is the timeout function for thread, normally which is invoked
870-
* when thread is timeout to wait some resource.
898+
* @brief This function is the timeout function for thread, normally which is invoked
899+
* when thread is timeout to wait some resource.
871900
*
872-
* @param parameter the parameter of thread timeout function
901+
* @param parameter is the parameter of thread timeout function
873902
*/
874903
void rt_thread_timeout(void *parameter)
875904
{
@@ -904,18 +933,20 @@ void rt_thread_timeout(void *parameter)
904933
RTM_EXPORT(rt_thread_timeout);
905934

906935
/**
907-
* This function will find the specified thread.
936+
* @brief This function will find the specified thread.
908937
*
909-
* @param name the name of thread finding
938+
* @note Please don't invoke this function in interrupt status.
910939
*
911-
* @return the found thread
940+
* @param name is the name of thread finding.
912941
*
913-
* @note please don't invoke this function in interrupt status.
942+
* @return If the return value is a rt_thread structure pointer, the function is successfully executed.
943+
* If the return value is RT_NULL, it means this operation failed.
914944
*/
915945
rt_thread_t rt_thread_find(char *name)
916946
{
917947
return (rt_thread_t)rt_object_find(name, RT_Object_Class_Thread);
918948
}
949+
919950
RTM_EXPORT(rt_thread_find);
920951

921952
/**@}*/

0 commit comments

Comments
 (0)