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


Ignore:
Timestamp:
2023-02-10T22:59:11Z (2 years ago)
Author:
Jiří Zárevúcky <zarevucky.jiri@…>
Branches:
master, ticket/834-toolchain-update, topic/msim-upgrade, topic/simplify-dev-export
Children:
11d2c983
Parents:
daadfa6
git-author:
Jiří Zárevúcky <zarevucky.jiri@…> (2023-02-10 22:53:12)
git-committer:
Jiří Zárevúcky <zarevucky.jiri@…> (2023-02-10 22:59:11)
Message:

Make thread_t reference counted

This simplifies interaction between various locks and thread
lifespan, which simplifies things. For example, threads_lock can
now simply be a mutex protecting the global it was made for, and
nothing more.

File:
1 edited

Legend:

Unmodified
Added
Removed
  • kernel/generic/include/proc/thread.h

    rdaadfa6 r1871118  
    7070/** Thread structure. There is one per thread. */
    7171typedef struct thread {
     72        atomic_refcount_t refcount;
     73
    7274        link_t rq_link;  /**< Run queue link. */
    7375        link_t wq_link;  /**< Wait queue link. */
     
    7779        odlink_t lthreads;
    7880
     81        /**
     82         * If true, the thread is terminating.
     83         * It will not go to sleep in interruptible synchronization functions
     84         * and will call thread_exit() before returning to userspace.
     85         */
     86        volatile bool interrupted;
     87
     88        /** Waitq for thread_join_timeout(). */
     89        waitq_t join_wq;
     90
    7991        /** Lock protecting thread structure.
    8092         *
    81          * Protects the whole thread structure except list links above.
     93         * Protects the whole thread structure except fields listed above.
    8294         */
    8395        IRQ_SPINLOCK_DECLARE(lock);
     
    133145         */
    134146        bool in_copy_to_uspace;
    135 
    136         /**
    137          * If true, the thread will not go to sleep at all and will call
    138          * thread_exit() before returning to userspace.
    139          */
    140         bool interrupted;
    141 
    142         /** If true, thread_join_timeout() cannot be used on this thread. */
    143         bool detached;
    144         /** Waitq for thread_join_timeout(). */
    145         waitq_t join_wq;
    146         /** Link used in the joiner_head list. */
    147         link_t joiner_link;
    148147
    149148#ifdef CONFIG_FPU
     
    219218extern void thread_interrupt(thread_t *, bool);
    220219
     220static inline thread_t *thread_ref(thread_t *thread)
     221{
     222        refcount_up(&thread->refcount);
     223        return thread;
     224}
     225
     226static inline thread_t *thread_try_ref(thread_t *thread)
     227{
     228        if (refcount_try_up(&thread->refcount))
     229                return thread;
     230        else
     231                return NULL;
     232}
     233
     234extern void thread_put(thread_t *);
     235
    221236#ifndef thread_create_arch
    222237extern errno_t thread_create_arch(thread_t *, thread_flags_t);
     
    236251extern errno_t thread_join(thread_t *);
    237252extern errno_t thread_join_timeout(thread_t *, uint32_t, unsigned int);
    238 extern void thread_detach(thread_t *);
    239253
    240254extern void thread_print_list(bool);
    241 extern void thread_destroy(thread_t *, bool);
    242255extern thread_t *thread_find_by_id(thread_id_t);
    243256extern size_t thread_count(void);
     
    245258extern thread_t *thread_next(thread_t *);
    246259extern void thread_update_accounting(bool);
    247 extern bool thread_exists(thread_t *);
     260extern thread_t *thread_try_get(thread_t *);
    248261
    249262extern void thread_migration_disable(void);
Note: See TracChangeset for help on using the changeset viewer.