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

Unified Diff: base/worker_pool_mac.mm

Issue 5682008: Make members of Singleton<T> private and only visible to the singleton type. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: . Created 10 years 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 side-by-side diff with in-line comments
Download patch
Index: base/worker_pool_mac.mm
diff --git a/base/worker_pool_mac.mm b/base/worker_pool_mac.mm
index bbc789265d7b81c819f63055209978481f9622ac..956cfb4984ea2c63b2211157f8763f6513bfced6 100644
--- a/base/worker_pool_mac.mm
+++ b/base/worker_pool_mac.mm
@@ -4,11 +4,12 @@
#include "base/worker_pool_mac.h"
+#include "base/lazy_instance.h"
#include "base/logging.h"
#include "base/mac/scoped_nsautorelease_pool.h"
#include "base/metrics/histogram.h"
+#include "base/scoped_nsobject.h"
#include "base/scoped_ptr.h"
-#import "base/singleton_objc.h"
#include "base/task.h"
#include "base/third_party/dynamic_annotations/dynamic_annotations.h"
#include "base/worker_pool_linux.h"
@@ -34,6 +35,18 @@ std::vector<id> outstanding_ops_; // Outstanding operations at last check.
size_t running_ = 0; // Operations in |Run()|.
size_t outstanding_ = 0; // Operations posted but not completed.
+// We use a wrapper struct here for the NSOperationQueue so that the object
+// can be released when LazyInstance calls our destructor.
+struct NSOperationQueueWrapper {
+ NSOperationQueueWrapper() {
+ operation_queue.reset([[NSOperationQueue alloc] init]);
+ }
+ scoped_nsobject<NSOperationQueue> operation_queue;
+};
+
+static base::LazyInstance<NSOperationQueueWrapper> g_nsoperation_queue(
Evan Martin 2010/12/13 17:38:30 *
+ base::LINKER_INITIALIZED);
+
} // namespace
namespace worker_pool_mac {
@@ -47,7 +60,7 @@ void SetUseLinuxWorkerPool(bool flag) {
@implementation WorkerPoolObjC
+ (NSOperationQueue*)sharedOperationQueue {
- return SingletonObjC<NSOperationQueue>::get();
+ return g_nsoperation_queue.Get().operation_queue.get();
}
@end // @implementation WorkerPoolObjC

Powered by Google App Engine
This is Rietveld 408576698