mirror of
https://github.com/switchbrew/libnx.git
synced 2025-06-21 12:32:40 +02:00
36 lines
566 B
C
36 lines
566 B
C
// Copyright 2018 plutoo
|
|
#include "kernel/mutex.h"
|
|
#include "kernel/rwlock.h"
|
|
|
|
void rwlockInit(RwLock* r) {
|
|
rmutexInit(&r->r);
|
|
rmutexInit(&r->g);
|
|
r->b = 0;
|
|
}
|
|
|
|
void rwlockReadLock(RwLock* r) {
|
|
rmutexLock(&r->r);
|
|
|
|
if (r->b++ == 0)
|
|
rmutexLock(&r->g);
|
|
|
|
rmutexUnlock(&r->r);
|
|
}
|
|
|
|
void rwlockReadUnlock(RwLock* r) {
|
|
rmutexLock(&r->r);
|
|
|
|
if (r->b-- == 1)
|
|
rmutexUnlock(&r->g);
|
|
|
|
rmutexUnlock(&r->r);
|
|
}
|
|
|
|
void rwlockWriteLock(RwLock* r) {
|
|
rmutexLock(&r->g);
|
|
}
|
|
|
|
void rwlockWriteUnlock(RwLock* r) {
|
|
rmutexUnlock(&r->g);
|
|
}
|