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/lib/refcount.h

    rdaadfa6 r1871118  
    7676}
    7777
     78/**
     79 * Try to upgrade a weak reference.
     80 * Naturally, this is contingent on another form of synchronization being used
     81 * to ensure that the object continues to exist while the weak reference is in
     82 * use.
     83 */
     84static inline bool refcount_try_up(atomic_refcount_t *rc)
     85{
     86        int cnt = atomic_load_explicit(&rc->__cnt, memory_order_relaxed);
     87
     88        while (cnt >= 0) {
     89                if (atomic_compare_exchange_weak_explicit(&rc->__cnt, &cnt, cnt + 1,
     90                    memory_order_relaxed, memory_order_relaxed)) {
     91                        return true;
     92                }
     93        }
     94
     95        return false;
     96}
     97
    7898static inline bool refcount_unique(atomic_refcount_t *rc)
    7999{
Note: See TracChangeset for help on using the changeset viewer.