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/worker_pool_mac.h" | 5 #include "base/worker_pool_mac.h" |
6 | 6 |
7 #include "base/logging.h" | 7 #include "base/logging.h" |
8 #include "base/mac/scoped_nsautorelease_pool.h" | 8 #include "base/mac/scoped_nsautorelease_pool.h" |
9 #include "base/metrics/histogram.h" | 9 #include "base/metrics/histogram.h" |
| 10 #include "base/scoped_nsobject.h" |
10 #include "base/scoped_ptr.h" | 11 #include "base/scoped_ptr.h" |
11 #import "base/singleton_objc.h" | 12 #import "base/singleton_objc.h" |
12 #include "base/task.h" | 13 #include "base/task.h" |
13 #include "base/third_party/dynamic_annotations/dynamic_annotations.h" | 14 #include "base/third_party/dynamic_annotations/dynamic_annotations.h" |
14 #include "base/worker_pool_linux.h" | 15 #include "base/worker_pool_linux.h" |
15 | 16 |
16 // When C++ exceptions are disabled, the C++ library defines |try| and | 17 // When C++ exceptions are disabled, the C++ library defines |try| and |
17 // |catch| so as to allow exception-expecting C++ code to build properly when | 18 // |catch| so as to allow exception-expecting C++ code to build properly when |
18 // language support for exceptions is not present. These macros interfere | 19 // language support for exceptions is not present. These macros interfere |
19 // with the use of |@try| and |@catch| in Objective-C files such as this one. | 20 // with the use of |@try| and |@catch| in Objective-C files such as this one. |
20 // Undefine these macros here, after everything has been #included, since | 21 // Undefine these macros here, after everything has been #included, since |
21 // there will be no C++ uses and only Objective-C uses from this point on. | 22 // there will be no C++ uses and only Objective-C uses from this point on. |
22 #undef try | 23 #undef try |
23 #undef catch | 24 #undef catch |
24 | 25 |
25 namespace { | 26 namespace { |
26 | 27 |
27 // |true| to use the Linux WorkerPool implementation for | 28 // |true| to use the Linux WorkerPool implementation for |
28 // |WorkerPool::PostTask()|. | 29 // |WorkerPool::PostTask()|. |
29 bool use_linux_workerpool_ = true; | 30 bool use_linux_workerpool_ = true; |
30 | 31 |
31 Lock lock_; | 32 Lock lock_; |
32 base::Time last_check_; // Last hung-test check. | 33 base::Time last_check_; // Last hung-test check. |
33 std::vector<id> outstanding_ops_; // Outstanding operations at last check. | 34 std::vector<id> outstanding_ops_; // Outstanding operations at last check. |
34 size_t running_ = 0; // Operations in |Run()|. | 35 size_t running_ = 0; // Operations in |Run()|. |
35 size_t outstanding_ = 0; // Operations posted but not completed. | 36 size_t outstanding_ = 0; // Operations posted but not completed. |
36 | 37 |
| 38 // We use a wrapper struct here for the NSOperationQueue so that the object |
| 39 // can be released when LazyInstance calls our destructor. |
| 40 struct NSOperationQueueWrapper { |
| 41 NSOperationQueueWrapper() { |
| 42 operation_queue.reset([[NSOperationQueue alloc] init]); |
| 43 } |
| 44 scoped_nsobject<NSOperationQueue> operation_queue; |
| 45 }; |
| 46 |
| 47 static base::LazyInstance<NSOperationQueueWrapper> g_nsoperation_queue( |
| 48 base::LINKER_INITIALIZED); |
| 49 |
37 } // namespace | 50 } // namespace |
38 | 51 |
39 namespace worker_pool_mac { | 52 namespace worker_pool_mac { |
40 | 53 |
41 void SetUseLinuxWorkerPool(bool flag) { | 54 void SetUseLinuxWorkerPool(bool flag) { |
42 use_linux_workerpool_ = flag; | 55 use_linux_workerpool_ = flag; |
43 } | 56 } |
44 | 57 |
45 } // namespace worker_pool_mac | 58 } // namespace worker_pool_mac |
46 | 59 |
47 @implementation WorkerPoolObjC | 60 @implementation WorkerPoolObjC |
48 | 61 |
49 + (NSOperationQueue*)sharedOperationQueue { | 62 + (NSOperationQueue*)sharedOperationQueue { |
50 return SingletonObjC<NSOperationQueue>::get(); | 63 return g_nsoperation_queue.Get().operation_queue.get(); |
51 } | 64 } |
52 | 65 |
53 @end // @implementation WorkerPoolObjC | 66 @end // @implementation WorkerPoolObjC |
54 | 67 |
55 // TaskOperation adapts Task->Run() for use in an NSOperationQueue. | 68 // TaskOperation adapts Task->Run() for use in an NSOperationQueue. |
56 @interface TaskOperation : NSOperation { | 69 @interface TaskOperation : NSOperation { |
57 @private | 70 @private |
58 scoped_ptr<Task> task_; | 71 scoped_ptr<Task> task_; |
59 } | 72 } |
60 | 73 |
(...skipping 135 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
196 // Don't report "nothing to report". | 209 // Don't report "nothing to report". |
197 const size_t kUnaccountedOpsDelta = 10; | 210 const size_t kUnaccountedOpsDelta = 10; |
198 if (hung_ops.size() > 0 || outstanding_delta > kUnaccountedOpsDelta) { | 211 if (hung_ops.size() > 0 || outstanding_delta > kUnaccountedOpsDelta) { |
199 UMA_HISTOGRAM_COUNTS_100("OSX.HungWorkers", hung_ops.size()); | 212 UMA_HISTOGRAM_COUNTS_100("OSX.HungWorkers", hung_ops.size()); |
200 UMA_HISTOGRAM_COUNTS_100("OSX.OutstandingDelta", outstanding_delta); | 213 UMA_HISTOGRAM_COUNTS_100("OSX.OutstandingDelta", outstanding_delta); |
201 UMA_HISTOGRAM_COUNTS_100("OSX.RunningOps", running_ops); | 214 UMA_HISTOGRAM_COUNTS_100("OSX.RunningOps", running_ops); |
202 } | 215 } |
203 | 216 |
204 return true; | 217 return true; |
205 } | 218 } |
OLD | NEW |