> On 14 Sep 2026, at 14:32, Haakon Bugge <[email protected]> wrote:
> 
> On 14 Sep 2026, at 11:35, David Laight <[email protected]> wrote:

[snip]

>> If you use change the MX_ATOMIC_ADD to use the atomic_long functions
>> (I've forgotten the exact name) then all the counter are the same type
>> and can be removed from the union.
>> The default 'just use +=' code can then be moved to the bottom of mx_add().
> 
> That is a good idea, but we then misses test coverage for atomic_t. But,
> what about:

[snip]

I ended up with:

struct mx_elem {
        /* This union contains locks and lock-free data types */
        union {
                spinlock_t spinlock;
                rwlock_t rwlock;
                struct mutex mutex;
                atomic_t atomic_lock;
                atomic_t atomic_counter;
                atomic64_t atomic64_counter;
                long cmpxchg_counter;
                unsigned long bits;
                struct ww_mutex ww_mutex;
                struct optimistic_spin_queue osq_lock;
        };
        /* A counter protected by one of the locks above */
        long counter;
};

This became quite simpler. I'll test somewhat more, and send out
a v2 tomorrow.


Thxs, HÃ¥kon

Reply via email to