Skip to content

Commit af96694

Browse files
committed
kernel: Clarify timeout and sleep API regarding negative inputs
Timeout and use s32_t as an argument but only positive values are accepted (or special value like K_FOREVER). It was not specified in the description which may lead to misinterpretation. Signed-off-by: Krzysztof Chruscinski <[email protected]>
1 parent 8892406 commit af96694

File tree

1 file changed

+43
-33
lines changed

1 file changed

+43
-33
lines changed

include/kernel.h

Lines changed: 43 additions & 33 deletions
Original file line numberDiff line numberDiff line change
@@ -2020,8 +2020,9 @@ extern void k_queue_merge_slist(struct k_queue *queue, sys_slist_t *list);
20202020
* @note Can be called by ISRs, but @a timeout must be set to K_NO_WAIT.
20212021
*
20222022
* @param queue Address of the queue.
2023-
* @param timeout Waiting period to obtain a data item (in milliseconds),
2024-
* or one of the special values K_NO_WAIT and K_FOREVER.
2023+
* @param timeout Non-negative waiting period to obtain a data item (in
2024+
* milliseconds), or one of the special values K_NO_WAIT and
2025+
* K_FOREVER.
20252026
*
20262027
* @return Address of the data item if successful; NULL if returned
20272028
* without waiting, or waiting period timed out.
@@ -2188,8 +2189,8 @@ struct z_futex_data {
21882189
* @param futex Address of the futex.
21892190
* @param expected Expected value of the futex, if it is different the caller
21902191
* will not wait on it.
2191-
* @param timeout Waiting period on the futex, in milliseconds, or one of the
2192-
* special values K_NO_WAIT or K_FOREVER.
2192+
* @param timeout Non-negative waiting period on the futex, in milliseconds, or
2193+
* one of the special values K_NO_WAIT or K_FOREVER.
21932194
* @retval -EACCES Caller does not have read access to futex address.
21942195
* @retval -EAGAIN If the futex value did not match the expected parameter.
21952196
* @retval -EINVAL Futex parameter address not recognized by the kernel.
@@ -2653,15 +2654,17 @@ __syscall void k_stack_push(struct k_stack *stack, stack_data_t data);
26532654
*
26542655
* @param stack Address of the stack.
26552656
* @param data Address of area to hold the value popped from the stack.
2656-
* @param timeout Waiting period to obtain a value (in milliseconds),
2657-
* or one of the special values K_NO_WAIT and K_FOREVER.
2657+
* @param timeout Non-negative waiting period to obtain a value (in
2658+
* milliseconds), or one of the special values K_NO_WAIT and
2659+
* K_FOREVER.
26582660
*
26592661
* @retval 0 Element popped from stack.
26602662
* @retval -EBUSY Returned without waiting.
26612663
* @retval -EAGAIN Waiting period timed out.
26622664
* @req K-STACK-001
26632665
*/
2664-
__syscall int k_stack_pop(struct k_stack *stack, stack_data_t *data, s32_t timeout);
2666+
__syscall int k_stack_pop(struct k_stack *stack, stack_data_t *data,
2667+
s32_t timeout);
26652668

26662669
/**
26672670
* @brief Statically define and initialize a stack
@@ -2966,7 +2969,8 @@ extern void k_delayed_work_init(struct k_delayed_work *work,
29662969
*
29672970
* @param work_q Address of workqueue.
29682971
* @param work Address of delayed work item.
2969-
* @param delay Delay before submitting the work item (in milliseconds).
2972+
* @param delay Non-negative delay before submitting the work item (in
2973+
* milliseconds).
29702974
*
29712975
* @retval 0 Work item countdown started.
29722976
* @retval -EINVAL Work item is being processed or has completed its work.
@@ -3050,7 +3054,8 @@ static inline void k_work_submit(struct k_work *work)
30503054
* @note Can be called by ISRs.
30513055
*
30523056
* @param work Address of delayed work item.
3053-
* @param delay Delay before submitting the work item (in milliseconds).
3057+
* @param delay Non-negative delay before submitting the work item (in
3058+
* milliseconds).
30543059
*
30553060
* @retval 0 Work item countdown started.
30563061
* @retval -EINVAL Work item is being processed or has completed its work.
@@ -3120,8 +3125,8 @@ extern void k_work_poll_init(struct k_work_poll *work,
31203125
* @param work Address of delayed work item.
31213126
* @param events An array of pointers to events which trigger the work.
31223127
* @param num_events The number of events in the array.
3123-
* @param timeout Timeout after which the work will be scheduled for
3124-
* execution even if not triggered.
3128+
* @param timeout Non-negative timeout after which the work will be scheduled
3129+
* for execution even if not triggered.
31253130
*
31263131
*
31273132
* @retval 0 Work item started watching for events.
@@ -3158,8 +3163,8 @@ extern int k_work_poll_submit_to_queue(struct k_work_q *work_q,
31583163
* @param work Address of delayed work item.
31593164
* @param events An array of pointers to events which trigger the work.
31603165
* @param num_events The number of events in the array.
3161-
* @param timeout Timeout after which the work will be scheduled for
3162-
* execution even if not triggered.
3166+
* @param timeout Non-negative timeout after which the work will be scheduled
3167+
* for execution even if not triggered.
31633168
*
31643169
* @retval 0 Work item started watching for events.
31653170
* @retval -EINVAL Work item is being processed or has completed its work.
@@ -3268,8 +3273,9 @@ __syscall void k_mutex_init(struct k_mutex *mutex);
32683273
* completes immediately and the lock count is increased by 1.
32693274
*
32703275
* @param mutex Address of the mutex.
3271-
* @param timeout Waiting period to lock the mutex (in milliseconds),
3272-
* or one of the special values K_NO_WAIT and K_FOREVER.
3276+
* @param timeout Non-negative waiting period to lock the mutex (in
3277+
* milliseconds), or one of the special values K_NO_WAIT and
3278+
* K_FOREVER.
32733279
*
32743280
* @retval 0 Mutex locked.
32753281
* @retval -EBUSY Returned without waiting.
@@ -3356,8 +3362,9 @@ __syscall void k_sem_init(struct k_sem *sem, unsigned int initial_count,
33563362
* @note Can be called by ISRs, but @a timeout must be set to K_NO_WAIT.
33573363
*
33583364
* @param sem Address of the semaphore.
3359-
* @param timeout Waiting period to take the semaphore (in milliseconds),
3360-
* or one of the special values K_NO_WAIT and K_FOREVER.
3365+
* @param timeout Non-negative waiting period to take the semaphore (in
3366+
* milliseconds), or one of the special values K_NO_WAIT and
3367+
* K_FOREVER.
33613368
*
33623369
* @note When porting code from the nanokernel legacy API to the new API, be
33633370
* careful with the return value of this function. The return value is the
@@ -3590,8 +3597,9 @@ void k_msgq_cleanup(struct k_msgq *q);
35903597
*
35913598
* @param q Address of the message queue.
35923599
* @param data Pointer to the message.
3593-
* @param timeout Waiting period to add the message (in milliseconds),
3594-
* or one of the special values K_NO_WAIT and K_FOREVER.
3600+
* @param timeout Non-negative waiting period to add the message (in
3601+
* milliseconds), or one of the special values K_NO_WAIT and
3602+
* K_FOREVER.
35953603
*
35963604
* @retval 0 Message sent.
35973605
* @retval -ENOMSG Returned without waiting or queue purged.
@@ -3610,8 +3618,9 @@ __syscall int k_msgq_put(struct k_msgq *q, void *data, s32_t timeout);
36103618
*
36113619
* @param q Address of the message queue.
36123620
* @param data Address of area to hold the received message.
3613-
* @param timeout Waiting period to receive the message (in milliseconds),
3614-
* or one of the special values K_NO_WAIT and K_FOREVER.
3621+
* @param timeout Non-negative waiting period to receive the message (in
3622+
* milliseconds), or one of the special values K_NO_WAIT and
3623+
* K_FOREVER.
36153624
*
36163625
* @retval 0 Message received.
36173626
* @retval -ENOMSG Returned without waiting.
@@ -3816,7 +3825,7 @@ extern void k_mbox_init(struct k_mbox *mbox);
38163825
*
38173826
* @param mbox Address of the mailbox.
38183827
* @param tx_msg Address of the transmit message descriptor.
3819-
* @param timeout Waiting period for the message to be received (in
3828+
* @param timeout Non-negative waiting period for the message to be received (in
38203829
* milliseconds), or one of the special values K_NO_WAIT
38213830
* and K_FOREVER. Once the message has been received,
38223831
* this routine waits as long as necessary for the message
@@ -3859,7 +3868,7 @@ extern void k_mbox_async_put(struct k_mbox *mbox, struct k_mbox_msg *tx_msg,
38593868
* @param rx_msg Address of the receive message descriptor.
38603869
* @param buffer Address of the buffer to receive data, or NULL to defer data
38613870
* retrieval and message disposal until later.
3862-
* @param timeout Waiting period for a message to be received (in
3871+
* @param timeout Non-negative waiting period for a message to be received (in
38633872
* milliseconds), or one of the special values K_NO_WAIT
38643873
* and K_FOREVER.
38653874
*
@@ -3911,8 +3920,8 @@ extern void k_mbox_data_get(struct k_mbox_msg *rx_msg, void *buffer);
39113920
* @param rx_msg Address of a receive message descriptor.
39123921
* @param pool Address of memory pool, or NULL to discard data.
39133922
* @param block Address of the area to hold memory pool block info.
3914-
* @param timeout Waiting period to wait for a memory pool block (in
3915-
* milliseconds), or one of the special values K_NO_WAIT
3923+
* @param timeout Non-negative waiting period to wait for a memory pool block
3924+
* (in milliseconds), or one of the special values K_NO_WAIT
39163925
* and K_FOREVER.
39173926
*
39183927
* @retval 0 Data retrieved.
@@ -4053,8 +4062,8 @@ __syscall int k_pipe_alloc_init(struct k_pipe *pipe, size_t size);
40534062
* @param bytes_to_write Size of data (in bytes).
40544063
* @param bytes_written Address of area to hold the number of bytes written.
40554064
* @param min_xfer Minimum number of bytes to write.
4056-
* @param timeout Waiting period to wait for the data to be written (in
4057-
* milliseconds), or one of the special values K_NO_WAIT
4065+
* @param timeout Non-negative waiting period to wait for the data to be written
4066+
* (in milliseconds), or one of the special values K_NO_WAIT
40584067
* and K_FOREVER.
40594068
*
40604069
* @retval 0 At least @a min_xfer bytes of data were written.
@@ -4077,8 +4086,8 @@ __syscall int k_pipe_put(struct k_pipe *pipe, void *data,
40774086
* @param bytes_to_read Maximum number of data bytes to read.
40784087
* @param bytes_read Address of area to hold the number of bytes read.
40794088
* @param min_xfer Minimum number of data bytes to read.
4080-
* @param timeout Waiting period to wait for the data to be read (in
4081-
* milliseconds), or one of the special values K_NO_WAIT
4089+
* @param timeout Non-negative waiting period to wait for the data to be read
4090+
* (in milliseconds), or one of the special values K_NO_WAIT
40824091
* and K_FOREVER.
40834092
*
40844093
* @retval 0 At least @a min_xfer bytes of data were read.
@@ -4208,7 +4217,7 @@ extern void k_mem_slab_init(struct k_mem_slab *slab, void *buffer,
42084217
*
42094218
* @param slab Address of the memory slab.
42104219
* @param mem Pointer to block address area.
4211-
* @param timeout Maximum time to wait for operation to complete
4220+
* @param timeout Non-negative waiting period to wait for operation to complete
42124221
* (in milliseconds). Use K_NO_WAIT to return without waiting,
42134222
* or K_FOREVER to wait as long as necessary.
42144223
*
@@ -4331,7 +4340,7 @@ struct k_mem_pool {
43314340
* @param pool Address of the memory pool.
43324341
* @param block Pointer to block descriptor for the allocated memory.
43334342
* @param size Amount of memory to allocate (in bytes).
4334-
* @param timeout Maximum time to wait for operation to complete
4343+
* @param timeout Non-negative waiting period to wait for operation to complete
43354344
* (in milliseconds). Use K_NO_WAIT to return without waiting,
43364345
* or K_FOREVER to wait as long as necessary.
43374346
*
@@ -4653,8 +4662,9 @@ extern void k_poll_event_init(struct k_poll_event *event, u32_t type,
46534662
*
46544663
* @param events An array of pointers to events to be polled for.
46554664
* @param num_events The number of events in the array.
4656-
* @param timeout Waiting period for an event to be ready (in milliseconds),
4657-
* or one of the special values K_NO_WAIT and K_FOREVER.
4665+
* @param timeout Non-negative waiting period for an event to be ready (in
4666+
* milliseconds), or one of the special values K_NO_WAIT and
4667+
* K_FOREVER.
46584668
*
46594669
* @retval 0 One or more events are ready.
46604670
* @retval -EAGAIN Waiting period timed out.

0 commit comments

Comments
 (0)