#include "condition_variable.hpp" #include "../time/time.hpp" sprawl::threading::ConditionVariable::ConditionVariable() : m_conditionVariable() { pthread_cond_init(&m_conditionVariable, nullptr); } sprawl::threading::ConditionVariable::~ConditionVariable() { pthread_cond_destroy(&m_conditionVariable); } void sprawl::threading::ConditionVariable::Wait(SharedLock& lock) { pthread_cond_wait(&m_conditionVariable, &lock.GetMutex()->GetNativeMutex()); } void sprawl::threading::ConditionVariable::WaitFor(SharedLock& lock, int64_t nanoseconds) { struct timespec ts; ts.tv_sec = time_t(sprawl::time::Convert(nanoseconds, sprawl::time::Resolution::Nanoseconds, sprawl::time::Resolution::Seconds)); int64_t secsAsNanosecs = sprawl::time::Convert(ts.tv_sec, sprawl::time::Resolution::Seconds, sprawl::time::Resolution::Nanoseconds); ts.tv_nsec = long(nanoseconds - secsAsNanosecs); pthread_cond_timedwait(&m_conditionVariable, &lock.GetMutex()->GetNativeMutex(), &ts); } void sprawl::threading::ConditionVariable::WaitUntil(SharedLock& lock, int64_t nanosecondTimestamp) { WaitFor(lock, nanosecondTimestamp - time::Now(time::Resolution::Nanoseconds)); } void sprawl::threading::ConditionVariable::Notify() { pthread_cond_signal(&m_conditionVariable); } void sprawl::threading::ConditionVariable::NotifyAll() { pthread_cond_broadcast(&m_conditionVariable); }
# | Change | User | Description | Committed | |
---|---|---|---|---|---|
#1 | 12508 | ShadauxCat |
-Added threading library. Currently only functional for Linux; Windows will fail to link. (I will fix this soon.) -Fixed missing move and copy constructors in List and ForwardList -Fixed broken move constructor in HashMap -Fixed missing const get() in HashMap -Fixed broken operator-> in ListIterator -Added sprawl::noncopyable -Added sketch headers for filesystem library -Made StringLiteral hashable, added special hashes for pointers and integers in murmur3 -Fixed compiler warning in async_network -Updated memory allocators to use new threading library for mutexes -Added accessibility to sprawl::StringLiteral to be able toa ccess its pointer and length and perform pointer comparisons #review-12504 |