1 // Copyright 2013 The Chromium Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file.
5 // This file contains helper classes for video accelerator unittests.
7 #ifndef CONTENT_COMMON_GPU_MEDIA_VIDEO_ACCELERATOR_UNITTEST_HELPERS_H_
8 #define CONTENT_COMMON_GPU_MEDIA_VIDEO_ACCELERATOR_UNITTEST_HELPERS_H_
12 #include "base/synchronization/condition_variable.h"
13 #include "base/synchronization/lock.h"
17 // Helper class allowing one thread to wait on a notification from another.
18 // If notifications come in faster than they are Wait()'d for, they are
19 // accumulated (so exactly as many Wait() calls will unblock as Notify() calls
20 // were made, regardless of order).
21 template <typename StateEnum
>
22 class ClientStateNotification
{
24 ClientStateNotification();
25 ~ClientStateNotification();
27 // Used to notify a single waiter of a ClientState.
28 void Notify(StateEnum state
);
29 // Used by waiters to wait for the next ClientState Notification.
34 base::ConditionVariable cv_
;
35 std::queue
<StateEnum
> pending_states_for_notification_
;
38 template <typename StateEnum
>
39 ClientStateNotification
<StateEnum
>::ClientStateNotification() : cv_(&lock_
) {}
41 template <typename StateEnum
>
42 ClientStateNotification
<StateEnum
>::~ClientStateNotification() {}
44 template <typename StateEnum
>
45 void ClientStateNotification
<StateEnum
>::Notify(StateEnum state
) {
46 base::AutoLock
auto_lock(lock_
);
47 pending_states_for_notification_
.push(state
);
51 template <typename StateEnum
>
52 StateEnum ClientStateNotification
<StateEnum
>::Wait() {
53 base::AutoLock
auto_lock(lock_
);
54 while (pending_states_for_notification_
.empty())
56 StateEnum ret
= pending_states_for_notification_
.front();
57 pending_states_for_notification_
.pop();
61 } // namespace content
63 #endif // CONTENT_COMMON_GPU_MEDIA_VIDEO_ACCELERATOR_UNITTEST_HELPERS_H_