Skip to content
Snippets Groups Projects
Commit 0062d82c authored by Deucе's avatar Deucе :ok_hand_tone4:
Browse files

Make rwlock wrappers static inline functions instead of macros.

This should avoid angering Coverity.
parent 124e6716
No related branches found
No related tags found
No related merge requests found
Pipeline #7753 failed
...@@ -224,7 +224,7 @@ rwlock_destroy(rwlock_t *lock) ...@@ -224,7 +224,7 @@ rwlock_destroy(rwlock_t *lock)
#elif defined(__unix__) #elif defined(__unix__)
// All macros... // All static inline functions
#else #else
......
...@@ -4,16 +4,51 @@ ...@@ -4,16 +4,51 @@
#if defined(__unix__) #if defined(__unix__)
#include <pthread.h> #include <pthread.h>
#include <stdbool.h>
typedef pthread_rwlock_t rwlock_t; typedef pthread_rwlock_t rwlock_t;
#define rwlock_init(lock) (pthread_rwlock_init(lock, NULL) == 0) static inline bool
#define rwlock_rdlock(lock) (pthread_rwlock_rdlock(lock) == 0) rwlock_init(rwlock_t *lock)
#define rwlock_tryrdlock(lock) (pthread_rwlock_tryrdlock(lock) == 0) {
#define rwlock_wrlock(lock) (pthread_rwlock_wrlock(lock) == 0) return pthread_rwlock_init(lock, NULL) == 0;
#define rwlock_trywrlock(lock) (pthread_rwlock_trywrlock(lock) == 0) }
#define rwlock_unlock(lock) (pthread_rwlock_unlock(lock) == 0)
#define rwlock_destroy(lock) (pthread_rwlock_destroy(lock) == 0) static inline bool
#define rwlock_destroy_ign(lock) ((void)pthread_rwlock_destroy(lock)) rwlock_rdlock(rwlock_t *lock)
{
return pthread_rwlock_rdlock(lock) == 0;
}
static inline bool
rwlock_tryrdlock(rwlock_t *lock)
{
return pthread_rwlock_tryrdlock(lock) == 0;
}
static inline bool
rwlock_wrlock(rwlock_t *lock)
{
return pthread_rwlock_wrlock(lock) == 0;
}
static inline bool
rwlock_trywrlock(rwlock_t *lock)
{
return pthread_rwlock_trywrlock(lock) == 0;
}
static inline bool
rwlock_unlock(rwlock_t *lock)
{
return pthread_rwlock_unlock(lock) == 0;
}
static inline bool
rwlock_destroy(rwlock_t *lock)
{
return pthread_rwlock_destroy(lock) == 0;
}
#elif defined(_WIN32) #elif defined(_WIN32)
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment