OLD | NEW |
1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. |
2 // Use of this source code is governed by a BSD-style license that can be | 2 // Use of this source code is governed by a BSD-style license that can be |
3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
4 | 4 |
5 #include "media/audio/scoped_task_runner_observer.h" | 5 #include "media/audio/scoped_task_runner_observer.h" |
6 | 6 |
7 #include "base/bind.h" | 7 #include "base/bind.h" |
8 #include "base/synchronization/waitable_event.h" | 8 #include "base/synchronization/waitable_event.h" |
9 | 9 |
10 namespace media { | 10 namespace media { |
(...skipping 13 matching lines...) Expand all Loading... |
24 base::WaitableEvent* done) { | 24 base::WaitableEvent* done) { |
25 // Note: |done| may be NULL. | 25 // Note: |done| may be NULL. |
26 if (task_runner_->BelongsToCurrentThread()) { | 26 if (task_runner_->BelongsToCurrentThread()) { |
27 base::MessageLoop* loop = base::MessageLoop::current(); | 27 base::MessageLoop* loop = base::MessageLoop::current(); |
28 if (enable) { | 28 if (enable) { |
29 loop->AddDestructionObserver(this); | 29 loop->AddDestructionObserver(this); |
30 } else { | 30 } else { |
31 loop->RemoveDestructionObserver(this); | 31 loop->RemoveDestructionObserver(this); |
32 } | 32 } |
33 } else { | 33 } else { |
34 base::WaitableEvent event(false, false); | 34 base::WaitableEvent event(base::WaitableEvent::ResetPolicy::AUTOMATIC, |
| 35 base::WaitableEvent::InitialState::NOT_SIGNALED); |
35 if (task_runner_->PostTask(FROM_HERE, | 36 if (task_runner_->PostTask(FROM_HERE, |
36 base::Bind(&ScopedTaskRunnerObserver::ObserveLoopDestruction, | 37 base::Bind(&ScopedTaskRunnerObserver::ObserveLoopDestruction, |
37 base::Unretained(this), enable, &event))) { | 38 base::Unretained(this), enable, &event))) { |
38 event.Wait(); | 39 event.Wait(); |
39 } else { | 40 } else { |
40 // The message loop's thread has already terminated, so no need to wait. | 41 // The message loop's thread has already terminated, so no need to wait. |
41 } | 42 } |
42 } | 43 } |
43 | 44 |
44 if (done) | 45 if (done) |
45 done->Signal(); | 46 done->Signal(); |
46 } | 47 } |
47 | 48 |
48 } // namespace media. | 49 } // namespace media. |
OLD | NEW |