Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(372)

Side by Side Diff: base/threading/thread.cc

Issue 1852433005: Convert //base to use std::unique_ptr (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: rebase after r384946 Created 4 years, 8 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
« no previous file with comments | « base/threading/thread.h ('k') | base/threading/thread_checker_unittest.cc » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
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 "base/threading/thread.h" 5 #include "base/threading/thread.h"
6 6
7 #include "base/bind.h" 7 #include "base/bind.h"
8 #include "base/lazy_instance.h" 8 #include "base/lazy_instance.h"
9 #include "base/location.h" 9 #include "base/location.h"
10 #include "base/synchronization/waitable_event.h" 10 #include "base/synchronization/waitable_event.h"
(...skipping 86 matching lines...) Expand 10 before | Expand all | Expand 10 after
97 id_event_.Reset(); 97 id_event_.Reset();
98 id_ = kInvalidThreadId; 98 id_ = kInvalidThreadId;
99 99
100 SetThreadWasQuitProperly(false); 100 SetThreadWasQuitProperly(false);
101 101
102 MessageLoop::Type type = options.message_loop_type; 102 MessageLoop::Type type = options.message_loop_type;
103 if (!options.message_pump_factory.is_null()) 103 if (!options.message_pump_factory.is_null())
104 type = MessageLoop::TYPE_CUSTOM; 104 type = MessageLoop::TYPE_CUSTOM;
105 105
106 message_loop_timer_slack_ = options.timer_slack; 106 message_loop_timer_slack_ = options.timer_slack;
107 scoped_ptr<MessageLoop> message_loop = MessageLoop::CreateUnbound( 107 std::unique_ptr<MessageLoop> message_loop =
108 type, options.message_pump_factory); 108 MessageLoop::CreateUnbound(type, options.message_pump_factory);
109 message_loop_ = message_loop.get(); 109 message_loop_ = message_loop.get();
110 start_event_.Reset(); 110 start_event_.Reset();
111 111
112 // Hold the thread_lock_ while starting a new thread, so that we can make sure 112 // Hold the thread_lock_ while starting a new thread, so that we can make sure
113 // that thread_ is populated before the newly created thread accesses it. 113 // that thread_ is populated before the newly created thread accesses it.
114 { 114 {
115 AutoLock lock(thread_lock_); 115 AutoLock lock(thread_lock_);
116 if (!PlatformThread::CreateWithPriority(options.stack_size, this, &thread_, 116 if (!PlatformThread::CreateWithPriority(options.stack_size, this, &thread_,
117 options.priority)) { 117 options.priority)) {
118 DLOG(ERROR) << "failed to create thread"; 118 DLOG(ERROR) << "failed to create thread";
(...skipping 101 matching lines...) Expand 10 before | Expand all | Expand 10 after
220 id_ = PlatformThread::CurrentId(); 220 id_ = PlatformThread::CurrentId();
221 DCHECK_NE(kInvalidThreadId, id_); 221 DCHECK_NE(kInvalidThreadId, id_);
222 id_event_.Signal(); 222 id_event_.Signal();
223 223
224 // Complete the initialization of our Thread object. 224 // Complete the initialization of our Thread object.
225 PlatformThread::SetName(name_.c_str()); 225 PlatformThread::SetName(name_.c_str());
226 ANNOTATE_THREAD_NAME(name_.c_str()); // Tell the name to race detector. 226 ANNOTATE_THREAD_NAME(name_.c_str()); // Tell the name to race detector.
227 227
228 // Lazily initialize the message_loop so that it can run on this thread. 228 // Lazily initialize the message_loop so that it can run on this thread.
229 DCHECK(message_loop_); 229 DCHECK(message_loop_);
230 scoped_ptr<MessageLoop> message_loop(message_loop_); 230 std::unique_ptr<MessageLoop> message_loop(message_loop_);
231 message_loop_->BindToCurrentThread(); 231 message_loop_->BindToCurrentThread();
232 message_loop_->set_thread_name(name_); 232 message_loop_->set_thread_name(name_);
233 message_loop_->SetTimerSlack(message_loop_timer_slack_); 233 message_loop_->SetTimerSlack(message_loop_timer_slack_);
234 234
235 #if defined(OS_WIN) 235 #if defined(OS_WIN)
236 scoped_ptr<win::ScopedCOMInitializer> com_initializer; 236 std::unique_ptr<win::ScopedCOMInitializer> com_initializer;
237 if (com_status_ != NONE) { 237 if (com_status_ != NONE) {
238 com_initializer.reset((com_status_ == STA) ? 238 com_initializer.reset((com_status_ == STA) ?
239 new win::ScopedCOMInitializer() : 239 new win::ScopedCOMInitializer() :
240 new win::ScopedCOMInitializer(win::ScopedCOMInitializer::kMTA)); 240 new win::ScopedCOMInitializer(win::ScopedCOMInitializer::kMTA));
241 } 241 }
242 #endif 242 #endif
243 243
244 // Let the thread do extra initialization. 244 // Let the thread do extra initialization.
245 Init(); 245 Init();
246 246
(...skipping 24 matching lines...) Expand all
271 // allow this. 271 // allow this.
272 DCHECK(GetThreadWasQuitProperly()); 272 DCHECK(GetThreadWasQuitProperly());
273 } 273 }
274 274
275 // We can't receive messages anymore. 275 // We can't receive messages anymore.
276 // (The message loop is destructed at the end of this block) 276 // (The message loop is destructed at the end of this block)
277 message_loop_ = nullptr; 277 message_loop_ = nullptr;
278 } 278 }
279 279
280 } // namespace base 280 } // namespace base
OLDNEW
« no previous file with comments | « base/threading/thread.h ('k') | base/threading/thread_checker_unittest.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698