| OLD | NEW |
| 1 // Copyright (c) 2010 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2010 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 "base/threading/simple_thread.h" | 5 #include "base/threading/simple_thread.h" |
| 6 | 6 |
| 7 #include "base/logging.h" | 7 #include "base/logging.h" |
| 8 #include "base/strings/string_number_conversions.h" | 8 #include "base/strings/string_number_conversions.h" |
| 9 #include "base/threading/platform_thread.h" | 9 #include "base/threading/platform_thread.h" |
| 10 #include "base/threading/thread_restrictions.h" | 10 #include "base/threading/thread_restrictions.h" |
| (...skipping 11 matching lines...) Expand all Loading... |
| 22 thread_(), event_(true, false), tid_(0), joined_(false) { | 22 thread_(), event_(true, false), tid_(0), joined_(false) { |
| 23 } | 23 } |
| 24 | 24 |
| 25 SimpleThread::~SimpleThread() { | 25 SimpleThread::~SimpleThread() { |
| 26 DCHECK(HasBeenStarted()) << "SimpleThread was never started."; | 26 DCHECK(HasBeenStarted()) << "SimpleThread was never started."; |
| 27 DCHECK(HasBeenJoined()) << "SimpleThread destroyed without being Join()ed."; | 27 DCHECK(HasBeenJoined()) << "SimpleThread destroyed without being Join()ed."; |
| 28 } | 28 } |
| 29 | 29 |
| 30 void SimpleThread::Start() { | 30 void SimpleThread::Start() { |
| 31 DCHECK(!HasBeenStarted()) << "Tried to Start a thread multiple times."; | 31 DCHECK(!HasBeenStarted()) << "Tried to Start a thread multiple times."; |
| 32 bool success = PlatformThread::Create(options_.stack_size(), this, &thread_); | 32 bool success; |
| 33 if (options_.priority() == ThreadPriority::NORMAL) { |
| 34 success = PlatformThread::Create(options_.stack_size(), this, &thread_); |
| 35 } else { |
| 36 success = PlatformThread::CreateWithPriority(options_.stack_size(), this, |
| 37 &thread_, options_.priority()); |
| 38 } |
| 33 DCHECK(success); | 39 DCHECK(success); |
| 34 base::ThreadRestrictions::ScopedAllowWait allow_wait; | 40 base::ThreadRestrictions::ScopedAllowWait allow_wait; |
| 35 event_.Wait(); // Wait for the thread to complete initialization. | 41 event_.Wait(); // Wait for the thread to complete initialization. |
| 36 } | 42 } |
| 37 | 43 |
| 38 void SimpleThread::Join() { | 44 void SimpleThread::Join() { |
| 39 DCHECK(HasBeenStarted()) << "Tried to Join a never-started thread."; | 45 DCHECK(HasBeenStarted()) << "Tried to Join a never-started thread."; |
| 40 DCHECK(!HasBeenJoined()) << "Tried to Join a thread multiple times."; | 46 DCHECK(!HasBeenJoined()) << "Tried to Join a thread multiple times."; |
| 41 PlatformThread::Join(thread_); | 47 PlatformThread::Join(thread_); |
| 42 joined_ = true; | 48 joined_ = true; |
| (...skipping 107 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 150 | 156 |
| 151 // A NULL delegate pointer signals us to quit. | 157 // A NULL delegate pointer signals us to quit. |
| 152 if (!work) | 158 if (!work) |
| 153 break; | 159 break; |
| 154 | 160 |
| 155 work->Run(); | 161 work->Run(); |
| 156 } | 162 } |
| 157 } | 163 } |
| 158 | 164 |
| 159 } // namespace base | 165 } // namespace base |
| OLD | NEW |