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

Side by Side Diff: base/threading/worker_pool_posix.h

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
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 // The thread pool used in the POSIX implementation of WorkerPool dynamically 5 // The thread pool used in the POSIX implementation of WorkerPool dynamically
6 // adds threads as necessary to handle all tasks. It keeps old threads around 6 // adds threads as necessary to handle all tasks. It keeps old threads around
7 // for a period of time to allow them to be reused. After this waiting period, 7 // for a period of time to allow them to be reused. After this waiting period,
8 // the threads exit. This thread pool uses non-joinable threads, therefore 8 // the threads exit. This thread pool uses non-joinable threads, therefore
9 // worker threads are not joined during process shutdown. This means that 9 // worker threads are not joined during process shutdown. This means that
10 // potentially long running tasks (such as DNS lookup) do not block process 10 // potentially long running tasks (such as DNS lookup) do not block process
11 // shutdown, but also means that process shutdown may "leak" objects. Note that 11 // shutdown, but also means that process shutdown may "leak" objects. Note that
12 // although PosixDynamicThreadPool spawns the worker threads and manages the 12 // although PosixDynamicThreadPool spawns the worker threads and manages the
13 // task queue, it does not own the worker threads. The worker threads ask the 13 // task queue, it does not own the worker threads. The worker threads ask the
14 // PosixDynamicThreadPool for work and eventually clean themselves up. The 14 // PosixDynamicThreadPool for work and eventually clean themselves up. The
15 // worker threads all maintain scoped_refptrs to the PosixDynamicThreadPool 15 // worker threads all maintain scoped_refptrs to the PosixDynamicThreadPool
16 // instance, which prevents PosixDynamicThreadPool from disappearing before all 16 // instance, which prevents PosixDynamicThreadPool from disappearing before all
17 // worker threads exit. The owner of PosixDynamicThreadPool should likewise 17 // worker threads exit. The owner of PosixDynamicThreadPool should likewise
18 // maintain a scoped_refptr to the PosixDynamicThreadPool instance. 18 // maintain a scoped_refptr to the PosixDynamicThreadPool instance.
19 // 19 //
20 // NOTE: The classes defined in this file are only meant for use by the POSIX 20 // NOTE: The classes defined in this file are only meant for use by the POSIX
21 // implementation of WorkerPool. No one else should be using these classes. 21 // implementation of WorkerPool. No one else should be using these classes.
22 // These symbols are exported in a header purely for testing purposes. 22 // These symbols are exported in a header purely for testing purposes.
23 23
24 #ifndef BASE_THREADING_WORKER_POOL_POSIX_H_ 24 #ifndef BASE_THREADING_WORKER_POOL_POSIX_H_
25 #define BASE_THREADING_WORKER_POOL_POSIX_H_ 25 #define BASE_THREADING_WORKER_POOL_POSIX_H_
26 26
27 #include <memory>
27 #include <queue> 28 #include <queue>
28 #include <string> 29 #include <string>
29 30
30 #include "base/callback_forward.h" 31 #include "base/callback_forward.h"
31 #include "base/location.h" 32 #include "base/location.h"
32 #include "base/macros.h" 33 #include "base/macros.h"
33 #include "base/memory/ref_counted.h" 34 #include "base/memory/ref_counted.h"
34 #include "base/memory/scoped_ptr.h"
35 #include "base/pending_task.h" 35 #include "base/pending_task.h"
36 #include "base/synchronization/condition_variable.h" 36 #include "base/synchronization/condition_variable.h"
37 #include "base/synchronization/lock.h" 37 #include "base/synchronization/lock.h"
38 #include "base/threading/platform_thread.h" 38 #include "base/threading/platform_thread.h"
39 #include "base/tracked_objects.h" 39 #include "base/tracked_objects.h"
40 40
41 class Task; 41 class Task;
42 42
43 namespace base { 43 namespace base {
44 44
(...skipping 36 matching lines...) Expand 10 before | Expand all | Expand 10 after
81 81
82 // Signal()s worker threads to let them know more tasks are available. 82 // Signal()s worker threads to let them know more tasks are available.
83 // Also used for Broadcast()'ing to worker threads to let them know the pool 83 // Also used for Broadcast()'ing to worker threads to let them know the pool
84 // is being deleted and they can exit. 84 // is being deleted and they can exit.
85 ConditionVariable pending_tasks_available_cv_; 85 ConditionVariable pending_tasks_available_cv_;
86 int num_idle_threads_; 86 int num_idle_threads_;
87 TaskQueue pending_tasks_; 87 TaskQueue pending_tasks_;
88 bool terminated_; 88 bool terminated_;
89 // Only used for tests to ensure correct thread ordering. It will always be 89 // Only used for tests to ensure correct thread ordering. It will always be
90 // NULL in non-test code. 90 // NULL in non-test code.
91 scoped_ptr<ConditionVariable> num_idle_threads_cv_; 91 std::unique_ptr<ConditionVariable> num_idle_threads_cv_;
92 92
93 DISALLOW_COPY_AND_ASSIGN(PosixDynamicThreadPool); 93 DISALLOW_COPY_AND_ASSIGN(PosixDynamicThreadPool);
94 }; 94 };
95 95
96 } // namespace base 96 } // namespace base
97 97
98 #endif // BASE_THREADING_WORKER_POOL_POSIX_H_ 98 #endif // BASE_THREADING_WORKER_POOL_POSIX_H_
OLDNEW
« no previous file with comments | « base/threading/thread_collision_warner_unittest.cc ('k') | base/timer/hi_res_timer_manager_unittest.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698