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