Changeset 111b9b9 in mainline for kernel/generic/src/time/timeout.c


Ignore:
Timestamp:
2023-02-11T19:13:44Z (20 months ago)
Author:
Jiří Zárevúcky <zarevucky.jiri@…>
Branches:
master, ticket/834-toolchain-update, topic/msim-upgrade, topic/simplify-dev-export
Children:
4777e02
Parents:
76e17d7c
git-author:
Jiří Zárevúcky <zarevucky.jiri@…> (2022-08-15 17:46:39)
git-committer:
Jiří Zárevúcky <zarevucky.jiri@…> (2023-02-11 19:13:44)
Message:

Reimplement waitq using thread_wait/wakeup

This adds a few functions to the thread API which can be
summarized as "stop running until woken up by others".
The ordering and context-switching concerns are thus yeeted
to this abstraction and waitq only deals with maintaining
the queues. Overall, this makes the control flow in waitq
much easier to navigate.

File:
1 edited

Legend:

Unmodified
Added
Removed
  • kernel/generic/src/time/timeout.c

    r76e17d7c r111b9b9  
    7171}
    7272
    73 /** Register timeout
    74  *
    75  * Insert timeout handler f (with argument arg)
    76  * to timeout list and make it execute in
    77  * time microseconds (or slightly more).
    78  *
    79  * @param timeout Timeout structure.
    80  * @param time    Number of usec in the future to execute the handler.
    81  * @param handler Timeout handler function.
    82  * @param arg     Timeout handler argument.
    83  *
    84  */
    85 void timeout_register(timeout_t *timeout, uint64_t time,
     73/* Only call when interrupts are disabled. */
     74deadline_t timeout_deadline_in_usec(uint32_t usec)
     75{
     76        if (usec == 0)
     77                return 0;
     78
     79        return CPU->current_clock_tick + us2ticks(usec);
     80}
     81
     82static void timeout_register_deadline_locked(timeout_t *timeout, deadline_t deadline,
    8683    timeout_handler_t handler, void *arg)
    8784{
    88         irq_spinlock_lock(&CPU->timeoutlock, true);
    89 
    9085        assert(!link_in_use(&timeout->link));
    9186
    9287        *timeout = (timeout_t) {
    9388                .cpu = CPU,
    94                 .deadline = CPU->current_clock_tick + us2ticks(time),
     89                .deadline = deadline,
    9590                .handler = handler,
    9691                .arg = arg,
     
    113108                }
    114109        }
     110}
    115111
     112/** Register timeout
     113 *
     114 * Insert timeout handler f (with argument arg)
     115 * to timeout list and make it execute in
     116 * time microseconds (or slightly more).
     117 *
     118 * @param timeout Timeout structure.
     119 * @param time    Number of usec in the future to execute the handler.
     120 * @param handler Timeout handler function.
     121 * @param arg     Timeout handler argument.
     122 *
     123 */
     124void timeout_register(timeout_t *timeout, uint64_t time,
     125    timeout_handler_t handler, void *arg)
     126{
     127        irq_spinlock_lock(&CPU->timeoutlock, true);
     128        timeout_register_deadline_locked(timeout, timeout_deadline_in_usec(time), handler, arg);
     129        irq_spinlock_unlock(&CPU->timeoutlock, true);
     130}
     131
     132void timeout_register_deadline(timeout_t *timeout, deadline_t deadline,
     133    timeout_handler_t handler, void *arg)
     134{
     135        irq_spinlock_lock(&CPU->timeoutlock, true);
     136        timeout_register_deadline_locked(timeout, deadline, handler, arg);
    116137        irq_spinlock_unlock(&CPU->timeoutlock, true);
    117138}
Note: See TracChangeset for help on using the changeset viewer.