#pragma once #include #include #include #ifdef __cplusplus extern "C" { #endif struct rt_rwlock; void rt_rwlock_rdlock(struct rt_rwlock *lock); bool rt_rwlock_tryrdlock(struct rt_rwlock *lock); bool rt_rwlock_timedrdlock(struct rt_rwlock *lock, unsigned long ticks); void rt_rwlock_rdunlock(struct rt_rwlock *lock); void rt_rwlock_wrlock(struct rt_rwlock *lock); bool rt_rwlock_trywrlock(struct rt_rwlock *lock); bool rt_rwlock_timedwrlock(struct rt_rwlock *lock, unsigned long ticks); void rt_rwlock_wrunlock(struct rt_rwlock *lock); void rt_rwlock_unlock(struct rt_rwlock *lock); struct rt_rwlock { rt_atomic_uint value; struct rt_mutex mutex; struct rt_cond cond; }; #define RT_RWLOCK_INIT(name) \ { \ .value = 0U, \ .mutex = RT_MUTEX_INIT(name.mutex), \ .cond = RT_COND_INIT(name.cond), \ } #define RT_RWLOCK(name) struct rt_rwlock name = RT_RWLOCK_INIT(name) #ifdef __cplusplus } #endif