From 625332e06437018bf696dce93a4b2bd2c5e0b118 Mon Sep 17 00:00:00 2001 From: "satish@chromium.org" Date: Tue, 14 Dec 2010 07:48:49 +0000 Subject: Make members of Singleton private and only visible to the singleton type. This enforces that the Singleton pattern can only be used within classes which want singleton-ness. As part of this CL I have also fixed up files which got missed in my previous CLs to use a GetInstance() method and use Singleton from the source file. There are a small number of places where I have also switched to LazyInstance as that was more appropriate for types used in a single source file. BUG=65298 TEST=all existing tests should continue to pass. Review URL: http://codereview.chromium.org/5682008 git-svn-id: svn://svn.chromium.org/chrome/trunk/src@69107 0039d316-1c4b-4281-b951-d872f2087c98 --- base/worker_pool_mac.mm | 17 +++++++++++++++-- 1 file changed, 15 insertions(+), 2 deletions(-) (limited to 'base/worker_pool_mac.mm') diff --git a/base/worker_pool_mac.mm b/base/worker_pool_mac.mm index bbc7892..956cfb4 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 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 operation_queue; +}; + +static base::LazyInstance g_nsoperation_queue( + base::LINKER_INITIALIZED); + } // namespace namespace worker_pool_mac { @@ -47,7 +60,7 @@ void SetUseLinuxWorkerPool(bool flag) { @implementation WorkerPoolObjC + (NSOperationQueue*)sharedOperationQueue { - return SingletonObjC::get(); + return g_nsoperation_queue.Get().operation_queue.get(); } @end // @implementation WorkerPoolObjC -- cgit v1.1