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/audio_device_thread.h" | 5 #include "media/audio/audio_device_thread.h" |
6 | 6 |
7 #include <algorithm> | 7 #include <algorithm> |
8 | 8 |
9 #include "base/bind.h" | 9 #include "base/bind.h" |
10 #include "base/logging.h" | 10 #include "base/logging.h" |
(...skipping 76 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
87 | 87 |
88 bool AudioDeviceThread::IsStopped() { | 88 bool AudioDeviceThread::IsStopped() { |
89 base::AutoLock auto_lock(thread_lock_); | 89 base::AutoLock auto_lock(thread_lock_); |
90 return thread_ == NULL; | 90 return thread_ == NULL; |
91 } | 91 } |
92 | 92 |
93 // AudioDeviceThread::Thread implementation | 93 // AudioDeviceThread::Thread implementation |
94 AudioDeviceThread::Thread::Thread(AudioDeviceThread::Callback* callback, | 94 AudioDeviceThread::Thread::Thread(AudioDeviceThread::Callback* callback, |
95 base::SyncSocket::Handle socket, | 95 base::SyncSocket::Handle socket, |
96 const char* thread_name) | 96 const char* thread_name) |
97 : thread_(base::kNullThreadHandle), | 97 : thread_(), |
98 callback_(callback), | 98 callback_(callback), |
99 socket_(socket), | 99 socket_(socket), |
100 thread_name_(thread_name) { | 100 thread_name_(thread_name) { |
101 } | 101 } |
102 | 102 |
103 AudioDeviceThread::Thread::~Thread() { | 103 AudioDeviceThread::Thread::~Thread() { |
104 DCHECK_EQ(thread_, base::kNullThreadHandle) << "Stop wasn't called"; | 104 DCHECK(thread_.is_null()); |
105 } | 105 } |
106 | 106 |
107 void AudioDeviceThread::Thread::Start() { | 107 void AudioDeviceThread::Thread::Start() { |
108 base::AutoLock auto_lock(callback_lock_); | 108 base::AutoLock auto_lock(callback_lock_); |
109 DCHECK_EQ(thread_, base::kNullThreadHandle); | 109 DCHECK(thread_.is_null()); |
110 // This reference will be released when the thread exists. | 110 // This reference will be released when the thread exists. |
111 AddRef(); | 111 AddRef(); |
112 | 112 |
113 PlatformThread::CreateWithPriority(0, this, &thread_, | 113 PlatformThread::CreateWithPriority(0, this, &thread_, |
114 base::kThreadPriority_RealtimeAudio); | 114 base::kThreadPriority_RealtimeAudio); |
115 CHECK(thread_ != base::kNullThreadHandle); | 115 CHECK(!thread_.is_null()); |
116 } | 116 } |
117 | 117 |
118 void AudioDeviceThread::Thread::Stop(base::MessageLoop* loop_for_join) { | 118 void AudioDeviceThread::Thread::Stop(base::MessageLoop* loop_for_join) { |
119 socket_.Shutdown(); | 119 socket_.Shutdown(); |
120 | 120 |
121 base::PlatformThreadHandle thread = base::kNullThreadHandle; | 121 base::PlatformThreadHandle thread = base::PlatformThreadHandle(); |
122 | 122 |
123 { // NOLINT | 123 { // NOLINT |
124 base::AutoLock auto_lock(callback_lock_); | 124 base::AutoLock auto_lock(callback_lock_); |
125 callback_ = NULL; | 125 callback_ = NULL; |
126 std::swap(thread, thread_); | 126 std::swap(thread, thread_); |
127 } | 127 } |
128 | 128 |
129 if (thread != base::kNullThreadHandle) { | 129 if (!thread.is_null()) { |
130 if (loop_for_join) { | 130 if (loop_for_join) { |
131 loop_for_join->PostTask(FROM_HERE, | 131 loop_for_join->PostTask(FROM_HERE, |
132 base::Bind(&base::PlatformThread::Join, thread)); | 132 base::Bind(&base::PlatformThread::Join, thread)); |
133 } else { | 133 } else { |
134 base::PlatformThread::Join(thread); | 134 base::PlatformThread::Join(thread); |
135 } | 135 } |
136 } | 136 } |
137 } | 137 } |
138 | 138 |
139 void AudioDeviceThread::Thread::ThreadMain() { | 139 void AudioDeviceThread::Thread::ThreadMain() { |
(...skipping 56 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
196 } | 196 } |
197 | 197 |
198 AudioDeviceThread::Callback::~Callback() {} | 198 AudioDeviceThread::Callback::~Callback() {} |
199 | 199 |
200 void AudioDeviceThread::Callback::InitializeOnAudioThread() { | 200 void AudioDeviceThread::Callback::InitializeOnAudioThread() { |
201 MapSharedMemory(); | 201 MapSharedMemory(); |
202 CHECK(shared_memory_.memory()); | 202 CHECK(shared_memory_.memory()); |
203 } | 203 } |
204 | 204 |
205 } // namespace media. | 205 } // namespace media. |
OLD | NEW |