/* * Copyright (c) 2023 Ali Mashtizadeh * All rights reserved. */ #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include void CV_Init(CV *cv, const char *name) { WaitChannel_Init(&cv->chan, name); return; } void CV_Destroy(CV *cv) { WaitChannel_Destroy(&cv->chan); return; } /** * CV_Wait -- * * Wait to be woken up on a condition. */ void CV_Wait(CV *cv, Mutex *mtx) { /* Do not go to sleep holding a spinlock! */ ASSERT(Critical_Level() == 0); WaitChannel_Lock(&cv->chan); Mutex_Unlock(mtx); WaitChannel_Sleep(&cv->chan); Mutex_Lock(mtx); return; } /** * CV_Signal -- * * Wake a single thread waiting on the condition. */ void CV_Signal(CV *cv) { WaitChannel_Wake(&cv->chan); return; } /** * CV_Broadcast -- * * Wake all threads waiting on the condition. */ void CV_Broadcast(CV *cv) { WaitChannel_WakeAll(&cv->chan); return; }