This commit is contained in:
Ren Kimura 2018-09-08 15:30:03 +00:00 committed by GitHub
commit 19a9069120
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23

View file

@ -24,15 +24,15 @@ class HosMutex {
HosMutex() {
mutexInit(&this->m);
}
void lock() {
mutexLock(&this->m);
}
void unlock() {
mutexUnlock(&this->m);
}
bool try_lock() {
return mutexTryLock(&this->m);
}
@ -45,15 +45,12 @@ class HosRecursiveMutex {
HosRecursiveMutex() {
rmutexInit(&this->m);
}
void lock() {
rmutexLock(&this->m);
}
void unlock() {
rmutexUnlock(&this->m);
}
bool try_lock() {
return rmutexTryLock(&this->m);
}
@ -66,25 +63,25 @@ class HosCondVar {
public:
HosCondVar() {
mutexInit(&m);
condvarInit(&cv, &m);
condvarInit(&cv);
}
Result WaitTimeout(u64 timeout) {
return condvarWaitTimeout(&cv, timeout);
return condvarWaitTimeout(&cv, &m, timeout);
}
Result Wait() {
return condvarWait(&cv);
return condvarWait(&cv, &m);
}
Result Wake(int num) {
return condvarWake(&cv, num);
}
Result WakeOne() {
return condvarWakeOne(&cv);
}
Result WakeAll() {
return condvarWakeAll(&cv);
}
@ -99,30 +96,30 @@ class HosSemaphore {
HosSemaphore() {
count = 0;
mutexInit(&m);
condvarInit(&cv, &m);
condvarInit(&cv);
}
HosSemaphore(u64 c) : count(c) {
mutexInit(&m);
condvarInit(&cv, &m);
condvarInit(&cv);
}
void Signal() {
mutexLock(&this->m);
count++;
condvarWakeOne(&cv);
mutexUnlock(&this->m);
}
void Wait() {
mutexLock(&this->m);
while (!count) {
condvarWait(&cv);
condvarWait(&cv, &m);
}
count--;
mutexUnlock(&this->m);
}
bool TryWait() {
mutexLock(&this->m);
bool success = false;