2013-10-28 12:48:13 -07:00
|
|
|
#ifndef AL_RWLOCK_H
|
|
|
|
#define AL_RWLOCK_H
|
|
|
|
|
2014-05-07 01:03:06 -07:00
|
|
|
#include "bool.h"
|
2013-10-28 12:48:13 -07:00
|
|
|
#include "atomic.h"
|
|
|
|
|
2014-05-29 04:22:30 -07:00
|
|
|
#ifdef __cplusplus
|
|
|
|
extern "C" {
|
|
|
|
#endif
|
|
|
|
|
2013-10-28 12:48:13 -07:00
|
|
|
typedef struct {
|
2014-05-14 02:47:07 -07:00
|
|
|
RefCount read_count;
|
|
|
|
RefCount write_count;
|
2016-11-25 23:25:16 -08:00
|
|
|
ATOMIC_FLAG read_lock;
|
|
|
|
ATOMIC_FLAG read_entry_lock;
|
|
|
|
ATOMIC_FLAG write_lock;
|
2013-10-28 12:48:13 -07:00
|
|
|
} RWLock;
|
2014-07-22 18:57:51 -07:00
|
|
|
#define RWLOCK_STATIC_INITIALIZE { ATOMIC_INIT_STATIC(0), ATOMIC_INIT_STATIC(0), \
|
2016-11-25 23:25:16 -08:00
|
|
|
ATOMIC_FLAG_INIT, ATOMIC_FLAG_INIT, ATOMIC_FLAG_INIT }
|
2013-10-28 12:48:13 -07:00
|
|
|
|
|
|
|
void RWLockInit(RWLock *lock);
|
|
|
|
void ReadLock(RWLock *lock);
|
|
|
|
void ReadUnlock(RWLock *lock);
|
|
|
|
void WriteLock(RWLock *lock);
|
|
|
|
void WriteUnlock(RWLock *lock);
|
|
|
|
|
2014-05-29 04:22:30 -07:00
|
|
|
#ifdef __cplusplus
|
|
|
|
}
|
|
|
|
#endif
|
|
|
|
|
2013-10-28 12:48:13 -07:00
|
|
|
#endif /* AL_RWLOCK_H */
|