Commit ad4ca0c4 authored by Max Kellermann's avatar Max Kellermann

thread/*Cond: remove wait() overloads without std::unique_lock<>

parent 0a0cc66e
......@@ -71,17 +71,13 @@ public:
pthread_cond_broadcast(&cond);
}
void wait(PosixMutex &mutex) noexcept {
pthread_cond_wait(&cond, &mutex.mutex);
}
template<typename M>
void wait(std::unique_lock<M> &lock) noexcept {
wait(*lock.mutex());
void wait(std::unique_lock<PosixMutex> &lock) noexcept {
pthread_cond_wait(&cond, &lock.mutex()->mutex);
}
private:
bool wait_for(PosixMutex &mutex, uint_least32_t timeout_us) noexcept {
bool wait_for(std::unique_lock<PosixMutex> &lock,
uint_least32_t timeout_us) noexcept {
struct timeval now;
gettimeofday(&now, nullptr);
......@@ -94,11 +90,12 @@ private:
ts.tv_sec++;
}
return pthread_cond_timedwait(&cond, &mutex.mutex, &ts) == 0;
return pthread_cond_timedwait(&cond, &lock.mutex()->mutex, &ts) == 0;
}
public:
bool wait_for(PosixMutex &mutex,
template<typename M>
bool wait_for(std::unique_lock<M> &lock,
std::chrono::steady_clock::duration timeout) noexcept {
auto timeout_us = std::chrono::duration_cast<std::chrono::microseconds>(timeout).count();
if (timeout_us < 0)
......@@ -106,13 +103,7 @@ public:
else if (timeout_us > std::numeric_limits<uint_least32_t>::max())
timeout_us = std::numeric_limits<uint_least32_t>::max();
return wait_for(mutex, timeout_us);
}
template<typename M>
bool wait_for(std::unique_lock<M> &lock,
std::chrono::steady_clock::duration timeout) noexcept {
return wait_for(*lock.mutex(), timeout);
return wait_for(lock, timeout_us);
}
};
......
......@@ -57,32 +57,18 @@ public:
WakeAllConditionVariable(&cond);
}
private:
bool wait_for(CriticalSection &mutex, DWORD timeout_ms) noexcept {
return SleepConditionVariableCS(&cond, &mutex.critical_section,
timeout_ms);
void wait(std::unique_lock<CriticalSection> &lock) noexcept {
SleepConditionVariableCS(&cond,
&lock.mutex()->critical_section,
INFINITE);
}
public:
bool wait_for(CriticalSection &mutex,
bool wait_for(std::unique_lock<CriticalSection> &lock,
std::chrono::steady_clock::duration timeout) noexcept {
auto timeout_ms = std::chrono::duration_cast<std::chrono::milliseconds>(timeout).count();
return wait_for(mutex, timeout_ms);
}
template<typename M>
bool wait_for(std::unique_lock<M> &lock,
std::chrono::steady_clock::duration timeout) noexcept {
return wait_for(*lock.mutex(), timeout);
}
void wait(CriticalSection &mutex) noexcept {
wait_for(mutex, INFINITE);
}
template<typename M>
void wait(std::unique_lock<M> &lock) noexcept {
wait(*lock.mutex());
return SleepConditionVariableCS(&cond,
&lock.mutex()->critical_section,
timeout_ms);
}
};
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment