mirror of
https://github.com/odin-lang/Odin.git
synced 2025-12-30 09:54:45 +00:00
Revert "Reimplement RwMutex on non-windows systems"
This reverts commit e9d20a9b4a.
This commit is contained in:
@@ -423,44 +423,28 @@ gb_internal void semaphore_wait(Semaphore *s) {
|
||||
}
|
||||
|
||||
struct RwMutex {
|
||||
BlockingMutex lock;
|
||||
Condition cond;
|
||||
int32_t readers;
|
||||
// TODO(bill): make this a proper RW mutex
|
||||
BlockingMutex mutex;
|
||||
};
|
||||
|
||||
gb_internal void rw_mutex_lock(RwMutex *m) {
|
||||
mutex_lock(&m->lock);
|
||||
while (m->readers != 0) {
|
||||
condition_wait(&m->cond, &m->lock);
|
||||
}
|
||||
mutex_lock(&m->mutex);
|
||||
}
|
||||
gb_internal bool rw_mutex_try_lock(RwMutex *m) {
|
||||
// TODO(bill): rw_mutex_try_lock
|
||||
rw_mutex_lock(m);
|
||||
return true;
|
||||
return mutex_try_lock(&m->mutex);
|
||||
}
|
||||
gb_internal void rw_mutex_unlock(RwMutex *m) {
|
||||
condition_signal(&m->cond);
|
||||
mutex_unlock(&m->lock);
|
||||
mutex_unlock(&m->mutex);
|
||||
}
|
||||
|
||||
gb_internal void rw_mutex_shared_lock(RwMutex *m) {
|
||||
mutex_lock(&m->lock);
|
||||
m->readers += 1;
|
||||
mutex_unlock(&m->lock);
|
||||
mutex_lock(&m->mutex);
|
||||
}
|
||||
gb_internal bool rw_mutex_try_shared_lock(RwMutex *m) {
|
||||
// TODO(bill): rw_mutex_try_shared_lock
|
||||
rw_mutex_shared_lock(m);
|
||||
return true;
|
||||
return mutex_try_lock(&m->mutex);
|
||||
}
|
||||
gb_internal void rw_mutex_shared_unlock(RwMutex *m) {
|
||||
mutex_lock(&m->lock);
|
||||
m->readers -= 1;
|
||||
if (m->readers == 0) {
|
||||
condition_signal(&m->cond);
|
||||
}
|
||||
mutex_unlock(&m->lock);
|
||||
mutex_unlock(&m->mutex);
|
||||
}
|
||||
#endif
|
||||
|
||||
|
||||
Reference in New Issue
Block a user