20 #include "pedigree/kernel/process/ConditionVariable.h" 21 #include "pedigree/kernel/LockGuard.h" 22 #include "pedigree/kernel/Log.h" 23 #include "pedigree/kernel/process/Mutex.h" 24 #include "pedigree/kernel/process/PerProcessorScheduler.h" 25 #include "pedigree/kernel/process/Thread.h" 26 #include "pedigree/kernel/processor/Processor.h" 27 #include "pedigree/kernel/processor/ProcessorInformation.h" 28 #include "pedigree/kernel/processor/types.h" 29 #include "pedigree/kernel/time/Time.h" 30 #include "pedigree/kernel/utilities/Iterator.h" 31 #include "pedigree/kernel/utilities/utility.h" 33 ConditionVariable::ConditionVariable() : m_Lock(false), m_Waiters()
37 ConditionVariable::~ConditionVariable()
44 Time::Timestamp zero = Time::Infinity;
45 return wait(mutex, zero);
51 Time::Timestamp startTime = Time::getTimeNanoseconds();
56 WARNING(
"ConditionVariable::wait called without a locked mutex");
63 m_Waiters.pushBack(me);
65 void *alarmHandle =
nullptr;
66 if (timeout != Time::Infinity)
68 alarmHandle = Time::addAlarm(timeout);
74 uintptr_t ra =
reinterpret_cast<uintptr_t
>(__builtin_return_address(0));
85 Time::removeAlarm(alarmHandle);
101 err = ThreadTerminating;
110 err = MutexNotAcquired;
114 Time::Timestamp endTime = Time::getTimeNanoseconds();
119 if (timeout != Time::Infinity)
121 Time::Timestamp timeConsumed = endTime - startTime;
122 if (timeConsumed >= timeout)
128 timeout -= timeConsumed;
139 for (
auto it = m_Waiters.begin(); it != m_Waiters.end();)
143 it = m_Waiters.erase(it);
162 if (!m_Waiters.count())
168 Thread *pThread = m_Waiters.popFront();
178 for (
auto pThread : m_Waiters)
180 pThread->getLock().acquire();
181 pThread->setStatus(Thread::Ready);
182 pThread->getLock().release();
bool acquire(size_t n=1, size_t timeoutSecs=0, size_t timeoutUsecs=0)
void setDebugState(DebugState state, uintptr_t address)
bool acquire(bool recurse=false, bool safe=true)
static ProcessorInformation & information()
No unwind necessary, carry on as normal.
void setInterrupted(bool b)
UnwindType getUnwindState()
WaitResult wait(Mutex &mutex, Time::Timestamp &timeout)