1234567891011121314151617181920212223242526272829303132333435 |
- #include "StdCondition.h"
- StdCondition::StdCondition():m_value(false)
- {
- }
- StdCondition::StdCondition(bool init):m_value(init)
- {
- }
- StdCondition::~StdCondition()
- {
- }
- bool StdCondition::isTrue(StdCondition* scd)
- {
- if (scd == 0)return false;
- return scd->m_value;
- }
- void StdCondition::Wait()
- {
- std::unique_lock<std::mutex> loc(m_mutex);
- m_cv.wait(loc,std::bind(isTrue,this));
- }
- bool StdCondition::WaitFor(unsigned int millisecond)
- {
- std::unique_lock<std::mutex> loc(m_mutex);
- return m_cv.wait_for(loc, std::chrono::milliseconds(millisecond), std::bind(isTrue, this));
- }
- void StdCondition::Notify(bool istrue)
- {
- std::unique_lock<std::mutex> loc(m_mutex);
- m_value = istrue;
- m_cv.notify_all();
- }
|