Changeset 111b9b9 in mainline for kernel/generic/include/proc/thread.h


Ignore:
Timestamp:
2023-02-11T19:13:44Z (22 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/include/proc/thread.h

    r76e17d7c r111b9b9  
    7979        odlink_t lthreads;
    8080
     81        /** Tracking variable for thread_wait/thread_wakeup */
     82        atomic_int sleep_state;
     83
    8184        /**
    8285         * If true, the thread is terminating.
     
    8588         */
    8689        volatile bool interrupted;
     90
     91        /** Wait queue in which this thread sleeps. Used for debug printouts. */
     92        _Atomic(waitq_t *) sleep_queue;
    8793
    8894        /** Waitq for thread_join_timeout(). */
     
    108114        context_t saved_context;
    109115        ipl_t saved_ipl;
    110 
    111         /**
    112          * From here, the stored timeout context
    113          * is restored when sleep times out.
    114          */
    115         context_t sleep_timeout_context;
    116 
    117         /**
    118          * From here, the stored interruption context
    119          * is restored when sleep is interrupted.
    120          */
    121         context_t sleep_interruption_context;
    122 
    123         /** If true, the thread can be interrupted from sleep. */
    124         bool sleep_interruptible;
    125 
    126         /**
    127          * If true, and this thread's sleep returns without a wakeup
    128          * (timed out or interrupted), waitq ignores the next wakeup.
    129          * This is necessary for futex to be able to handle those conditions.
    130          */
    131         bool sleep_composable;
    132 
    133         /** Wait queue in which this thread sleeps. */
    134         waitq_t *sleep_queue;
    135116
    136117        /**
     
    216197extern void thread_ready(thread_t *);
    217198extern void thread_exit(void) __attribute__((noreturn));
    218 extern void thread_interrupt(thread_t *, bool);
     199extern void thread_interrupt(thread_t *);
     200
     201typedef enum {
     202        THREAD_OK,
     203        THREAD_TERMINATING,
     204} thread_termination_state_t;
     205
     206typedef enum {
     207        THREAD_WAIT_SUCCESS,
     208        THREAD_WAIT_TIMEOUT,
     209} thread_wait_result_t;
     210
     211extern thread_termination_state_t thread_wait_start(void);
     212extern thread_wait_result_t thread_wait_finish(deadline_t);
     213extern void thread_wakeup(thread_t *);
    219214
    220215static inline thread_t *thread_ref(thread_t *thread)
Note: See TracChangeset for help on using the changeset viewer.