#ifndef CONTENT_COMMON_GPU_MEDIA_VIDEO_ACCELERATOR_UNITTEST_HELPERS_H_
#define CONTENT_COMMON_GPU_MEDIA_VIDEO_ACCELERATOR_UNITTEST_HELPERS_H_
#include <queue>
#include "base/synchronization/condition_variable.h"
#include "base/synchronization/lock.h"
namespace content {
template <typename StateEnum>
class ClientStateNotification {
public:
ClientStateNotification();
~ClientStateNotification();
void Notify(StateEnum state);
StateEnum Wait();
private:
base::Lock lock_;
base::ConditionVariable cv_;
std::queue<StateEnum> pending_states_for_notification_;
};
template <typename StateEnum>
ClientStateNotification<StateEnum>::ClientStateNotification() : cv_(&lock_) {}
template <typename StateEnum>
ClientStateNotification<StateEnum>::~ClientStateNotification() {}
template <typename StateEnum>
void ClientStateNotification<StateEnum>::Notify(StateEnum state) {
base::AutoLock auto_lock(lock_);
pending_states_for_notification_.push(state);
cv_.Signal();
}
template <typename StateEnum>
StateEnum ClientStateNotification<StateEnum>::Wait() {
base::AutoLock auto_lock(lock_);
while (pending_states_for_notification_.empty())
cv_.Wait();
StateEnum ret = pending_states_for_notification_.front();
pending_states_for_notification_.pop();
return ret;
}
}
#endif