summaryrefslogtreecommitdiffstats
path: root/base/worker_pool_mac.mm
diff options
context:
space:
mode:
authorsatish@chromium.org <satish@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98>2010-12-14 07:48:49 +0000
committersatish@chromium.org <satish@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98>2010-12-14 07:48:49 +0000
commit625332e06437018bf696dce93a4b2bd2c5e0b118 (patch)
tree56e128ddf94a81b6de1f29a9eabe59f0d79346c9 /base/worker_pool_mac.mm
parentdc7cdcb970254f223262a66c812f240a8269ae87 (diff)
downloadchromium_src-625332e06437018bf696dce93a4b2bd2c5e0b118.zip
chromium_src-625332e06437018bf696dce93a4b2bd2c5e0b118.tar.gz
chromium_src-625332e06437018bf696dce93a4b2bd2c5e0b118.tar.bz2
Make members of Singleton<T> private and only visible to the singleton type. This enforces that the Singleton<T> 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<T> 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
Diffstat (limited to 'base/worker_pool_mac.mm')
-rw-r--r--base/worker_pool_mac.mm17
1 files changed, 15 insertions, 2 deletions
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<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(
+ 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