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

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

Issue 2372583002: Enable the FileDescriptorWatcher API on MessageLoopForIO threads. (Closed)
Patch Set: fix build error Created 4 years, 2 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 | « no previous file | no next file » | 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/bind_helpers.h" 8 #include "base/bind_helpers.h"
9 #include "base/lazy_instance.h" 9 #include "base/lazy_instance.h"
10 #include "base/location.h" 10 #include "base/location.h"
11 #include "base/logging.h" 11 #include "base/logging.h"
12 #include "base/run_loop.h" 12 #include "base/run_loop.h"
13 #include "base/synchronization/waitable_event.h" 13 #include "base/synchronization/waitable_event.h"
14 #include "base/third_party/dynamic_annotations/dynamic_annotations.h" 14 #include "base/third_party/dynamic_annotations/dynamic_annotations.h"
15 #include "base/threading/thread_id_name_manager.h" 15 #include "base/threading/thread_id_name_manager.h"
16 #include "base/threading/thread_local.h" 16 #include "base/threading/thread_local.h"
17 #include "base/threading/thread_restrictions.h" 17 #include "base/threading/thread_restrictions.h"
18 #include "build/build_config.h" 18 #include "build/build_config.h"
19 19
20 #if defined(OS_POSIX) && !defined(OS_NACL)
21 #include "base/files/file_descriptor_watcher_posix.h"
22 #endif
23
20 #if defined(OS_WIN) 24 #if defined(OS_WIN)
21 #include "base/win/scoped_com_initializer.h" 25 #include "base/win/scoped_com_initializer.h"
22 #endif 26 #endif
23 27
24 namespace base { 28 namespace base {
25 29
26 namespace { 30 namespace {
27 31
28 // We use this thread-local variable to record whether or not a thread exited 32 // We use this thread-local variable to record whether or not a thread exited
29 // because its Stop method was called. This allows us to catch cases where 33 // because its Stop method was called. This allows us to catch cases where
(...skipping 258 matching lines...) Expand 10 before | Expand all | Expand 10 after
288 // Complete the initialization of our Thread object. 292 // Complete the initialization of our Thread object.
289 PlatformThread::SetName(name_.c_str()); 293 PlatformThread::SetName(name_.c_str());
290 ANNOTATE_THREAD_NAME(name_.c_str()); // Tell the name to race detector. 294 ANNOTATE_THREAD_NAME(name_.c_str()); // Tell the name to race detector.
291 295
292 // Lazily initialize the |message_loop| so that it can run on this thread. 296 // Lazily initialize the |message_loop| so that it can run on this thread.
293 DCHECK(message_loop_); 297 DCHECK(message_loop_);
294 std::unique_ptr<MessageLoop> message_loop(message_loop_); 298 std::unique_ptr<MessageLoop> message_loop(message_loop_);
295 message_loop_->BindToCurrentThread(); 299 message_loop_->BindToCurrentThread();
296 message_loop_->SetTimerSlack(message_loop_timer_slack_); 300 message_loop_->SetTimerSlack(message_loop_timer_slack_);
297 301
302 #if defined(OS_POSIX) && !defined(OS_NACL)
303 // Allow threads running a MessageLoopForIO to use FileDescriptorWatcher API.
304 std::unique_ptr<FileDescriptorWatcher> file_descriptor_watcher;
305 if (MessageLoopForIO::IsCurrent()) {
306 DCHECK_EQ(message_loop_, MessageLoopForIO::current());
307 file_descriptor_watcher.reset(
308 new FileDescriptorWatcher(MessageLoopForIO::current()));
309 }
310 #endif
311
298 #if defined(OS_WIN) 312 #if defined(OS_WIN)
299 std::unique_ptr<win::ScopedCOMInitializer> com_initializer; 313 std::unique_ptr<win::ScopedCOMInitializer> com_initializer;
300 if (com_status_ != NONE) { 314 if (com_status_ != NONE) {
301 com_initializer.reset((com_status_ == STA) ? 315 com_initializer.reset((com_status_ == STA) ?
302 new win::ScopedCOMInitializer() : 316 new win::ScopedCOMInitializer() :
303 new win::ScopedCOMInitializer(win::ScopedCOMInitializer::kMTA)); 317 new win::ScopedCOMInitializer(win::ScopedCOMInitializer::kMTA));
304 } 318 }
305 #endif 319 #endif
306 320
307 // Let the thread do extra initialization. 321 // Let the thread do extra initialization.
(...skipping 35 matching lines...) Expand 10 before | Expand all | Expand 10 after
343 run_loop_ = nullptr; 357 run_loop_ = nullptr;
344 } 358 }
345 359
346 void Thread::ThreadQuitHelper() { 360 void Thread::ThreadQuitHelper() {
347 DCHECK(run_loop_); 361 DCHECK(run_loop_);
348 run_loop_->QuitWhenIdle(); 362 run_loop_->QuitWhenIdle();
349 SetThreadWasQuitProperly(true); 363 SetThreadWasQuitProperly(true);
350 } 364 }
351 365
352 } // namespace base 366 } // namespace base
OLDNEW
« no previous file with comments | « no previous file | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698