summaryrefslogtreecommitdiffstats
path: root/media
diff options
context:
space:
mode:
authorepenner@chromium.org <epenner@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98>2013-05-22 00:01:38 +0000
committerepenner@chromium.org <epenner@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98>2013-05-22 00:01:38 +0000
commit54e6ff8ff7194e231fa5dfe49304574f189495ca (patch)
tree896f968b6eccc67a7c123b257a36bb7fa3fb918c /media
parent7fba3e550c138bf159589476c707a7e1d536055d (diff)
downloadchromium_src-54e6ff8ff7194e231fa5dfe49304574f189495ca.zip
chromium_src-54e6ff8ff7194e231fa5dfe49304574f189495ca.tar.gz
chromium_src-54e6ff8ff7194e231fa5dfe49304574f189495ca.tar.bz2
Reland: base: Support setting thread priorities generically.
This patch supports setting priorities across platforms at the PlatformThread level, by stashing thread id into the thread handle on linux/android. Since this adds more platform specific code, and #ifdefs were starting to get unwieldy, all platform specific code is moved into _platform.cc files, with the exception of the 'default' implementation, which stay in _posix. BUG=170549 Committed: https://src.chromium.org/viewvc/chrome?view=rev&revision=201202 Review URL: https://chromiumcodereview.appspot.com/12741012 git-svn-id: svn://svn.chromium.org/chrome/trunk/src@201389 0039d316-1c4b-4281-b951-d872f2087c98
Diffstat (limited to 'media')
-rw-r--r--media/audio/audio_device_thread.cc12
-rw-r--r--media/audio/cross_process_notification_win.cc10
-rw-r--r--media/filters/video_renderer_base.cc12
3 files changed, 18 insertions, 16 deletions
diff --git a/media/audio/audio_device_thread.cc b/media/audio/audio_device_thread.cc
index 7583c9e..f68c045 100644
--- a/media/audio/audio_device_thread.cc
+++ b/media/audio/audio_device_thread.cc
@@ -94,31 +94,31 @@ bool AudioDeviceThread::IsStopped() {
AudioDeviceThread::Thread::Thread(AudioDeviceThread::Callback* callback,
base::SyncSocket::Handle socket,
const char* thread_name)
- : thread_(base::kNullThreadHandle),
+ : thread_(),
callback_(callback),
socket_(socket),
thread_name_(thread_name) {
}
AudioDeviceThread::Thread::~Thread() {
- DCHECK_EQ(thread_, base::kNullThreadHandle) << "Stop wasn't called";
+ DCHECK(thread_.is_null());
}
void AudioDeviceThread::Thread::Start() {
base::AutoLock auto_lock(callback_lock_);
- DCHECK_EQ(thread_, base::kNullThreadHandle);
+ DCHECK(thread_.is_null());
// This reference will be released when the thread exists.
AddRef();
PlatformThread::CreateWithPriority(0, this, &thread_,
base::kThreadPriority_RealtimeAudio);
- CHECK(thread_ != base::kNullThreadHandle);
+ CHECK(!thread_.is_null());
}
void AudioDeviceThread::Thread::Stop(base::MessageLoop* loop_for_join) {
socket_.Shutdown();
- base::PlatformThreadHandle thread = base::kNullThreadHandle;
+ base::PlatformThreadHandle thread = base::PlatformThreadHandle();
{ // NOLINT
base::AutoLock auto_lock(callback_lock_);
@@ -126,7 +126,7 @@ void AudioDeviceThread::Thread::Stop(base::MessageLoop* loop_for_join) {
std::swap(thread, thread_);
}
- if (thread != base::kNullThreadHandle) {
+ if (!thread.is_null()) {
if (loop_for_join) {
loop_for_join->PostTask(FROM_HERE,
base::Bind(&base::PlatformThread::Join, thread));
diff --git a/media/audio/cross_process_notification_win.cc b/media/audio/cross_process_notification_win.cc
index 65e0e43..53bf0f4 100644
--- a/media/audio/cross_process_notification_win.cc
+++ b/media/audio/cross_process_notification_win.cc
@@ -121,7 +121,9 @@ class ExtraWaitThread : public base::PlatformThread::Delegate {
&events_[MAXIMUM_WAIT_OBJECTS - 2],
count_ - (MAXIMUM_WAIT_OBJECTS - 2),
&thread_signaled_event));
- base::PlatformThread::Create(0, extra_wait_thread.get(), &next_thread);
+ base::PlatformThreadHandle handle;
+ base::PlatformThread::Create(0, extra_wait_thread.get(), &handle);
+ next_thread = handle.platform_handle();
event_count = MAXIMUM_WAIT_OBJECTS;
events[MAXIMUM_WAIT_OBJECTS - 1] = next_thread;
@@ -140,7 +142,7 @@ class ExtraWaitThread : public base::PlatformThread::Delegate {
// so on), we must wait for ours to exit before we can check the
// propagated event offset.
if (next_thread) {
- base::PlatformThread::Join(next_thread);
+ base::PlatformThread::Join(base::PlatformThreadHandle(next_thread));
next_thread = NULL;
}
if (thread_signaled_event != -1)
@@ -156,7 +158,7 @@ class ExtraWaitThread : public base::PlatformThread::Delegate {
}
if (next_thread)
- base::PlatformThread::Join(next_thread);
+ base::PlatformThread::Join(base::PlatformThreadHandle(next_thread));
}
private:
@@ -232,7 +234,7 @@ int CrossProcessNotification::WaitMultiple(const Notifications& notifications,
base::PlatformThread::Create(0, &wait_thread, &thread);
HANDLE events[MAXIMUM_WAIT_OBJECTS];
std::copy(&handles[0], &handles[MAXIMUM_WAIT_OBJECTS - 1], &events[0]);
- events[MAXIMUM_WAIT_OBJECTS - 1] = thread;
+ events[MAXIMUM_WAIT_OBJECTS - 1] = thread.platform_handle();
wait = ::WaitForMultipleObjects(MAXIMUM_WAIT_OBJECTS, &events[0], FALSE,
INFINITE);
wait_failed = wait < WAIT_OBJECT_0 ||
diff --git a/media/filters/video_renderer_base.cc b/media/filters/video_renderer_base.cc
index f79e99d..84e48c4 100644
--- a/media/filters/video_renderer_base.cc
+++ b/media/filters/video_renderer_base.cc
@@ -35,7 +35,7 @@ VideoRendererBase::VideoRendererBase(
received_end_of_stream_(false),
frame_available_(&lock_),
state_(kUninitialized),
- thread_(base::kNullThreadHandle),
+ thread_(),
pending_read_(false),
drop_frames_(drop_frames),
playback_rate_(0),
@@ -48,7 +48,7 @@ VideoRendererBase::VideoRendererBase(
VideoRendererBase::~VideoRendererBase() {
base::AutoLock auto_lock(lock_);
CHECK(state_ == kStopped || state_ == kUninitialized) << state_;
- CHECK_EQ(thread_, base::kNullThreadHandle);
+ CHECK(thread_.is_null());
}
void VideoRendererBase::Play(const base::Closure& callback) {
@@ -100,15 +100,15 @@ void VideoRendererBase::Stop(const base::Closure& callback) {
DoStopOrError_Locked();
// Clean up our thread if present.
- base::PlatformThreadHandle thread_to_join = base::kNullThreadHandle;
- if (thread_ != base::kNullThreadHandle) {
+ base::PlatformThreadHandle thread_to_join = base::PlatformThreadHandle();
+ if (!thread_.is_null()) {
// Signal the thread since it's possible to get stopped with the video
// thread waiting for a read to complete.
frame_available_.Signal();
std::swap(thread_, thread_to_join);
}
- if (thread_to_join != base::kNullThreadHandle) {
+ if (!thread_to_join.is_null()) {
base::AutoUnlock auto_unlock(lock_);
base::PlatformThread::Join(thread_to_join);
}
@@ -212,7 +212,7 @@ void VideoRendererBase::OnVideoFrameStreamInitialized(bool success,
#if defined(OS_WIN)
// Bump up our priority so our sleeping is more accurate.
// TODO(scherkus): find out if this is necessary, but it seems to help.
- ::SetThreadPriority(thread_, THREAD_PRIORITY_ABOVE_NORMAL);
+ ::SetThreadPriority(thread_.platform_handle(), THREAD_PRIORITY_ABOVE_NORMAL);
#endif // defined(OS_WIN)
base::ResetAndReturn(&init_cb_).Run(PIPELINE_OK);
}