summaryrefslogtreecommitdiffstats
path: root/base/worker_pool_mac.mm
diff options
context:
space:
mode:
authormmentovai@google.com <mmentovai@google.com@0039d316-1c4b-4281-b951-d872f2087c98>2008-08-28 17:40:59 +0000
committermmentovai@google.com <mmentovai@google.com@0039d316-1c4b-4281-b951-d872f2087c98>2008-08-28 17:40:59 +0000
commitb060bd427af7ea65e6afc74d9aef3f055894154e (patch)
treecfbc2a1a7fb30dd82033ada58a6575582b9571c8 /base/worker_pool_mac.mm
parent7ec93dfb306b62e48cdf2498f4a2b5074074969a (diff)
downloadchromium_src-b060bd427af7ea65e6afc74d9aef3f055894154e.zip
chromium_src-b060bd427af7ea65e6afc74d9aef3f055894154e.tar.gz
chromium_src-b060bd427af7ea65e6afc74d9aef3f055894154e.tar.bz2
WorkerPool implementation for Mac, using NSOperationQueue
git-svn-id: svn://svn.chromium.org/chrome/trunk/src@1493 0039d316-1c4b-4281-b951-d872f2087c98
Diffstat (limited to 'base/worker_pool_mac.mm')
-rw-r--r--base/worker_pool_mac.mm72
1 files changed, 72 insertions, 0 deletions
diff --git a/base/worker_pool_mac.mm b/base/worker_pool_mac.mm
new file mode 100644
index 0000000..1147110
--- /dev/null
+++ b/base/worker_pool_mac.mm
@@ -0,0 +1,72 @@
+// Copyright (c) 2008 The Chromium Authors. All rights reserved.
+// Use of this source code is governed by a BSD-style license that can be
+// found in the LICENSE file.
+
+#include "base/worker_pool.h"
+
+#import <Foundation/Foundation.h>
+
+#include "base/logging.h"
+#import "base/singleton_objc.h"
+#include "base/task.h"
+
+// TaskOperation adapts Task->Run() for use in an NSOperationQueue.
+@interface TaskOperation : NSOperation {
+ @private
+ Task* task_; // (strong)
+}
+
+// Returns an autoreleased instance of TaskOperation. See -initWithTask: for
+// details.
++ (id)taskOperationWithTask:(Task*)task;
+
+// Designated initializer. |task| is adopted as the Task* whose Run method
+// this operation will call when executed.
+- (id)initWithTask:(Task*)task;
+
+@end
+
+@implementation TaskOperation
+
++ (id)taskOperationWithTask:(Task*)task {
+ return [[[TaskOperation alloc] initWithTask:task] autorelease];
+}
+
+- (id)init {
+ return [self initWithTask:NULL];
+}
+
+- (id)initWithTask:(Task*)task {
+ if ((self = [super init])) {
+ task_ = task;
+ }
+ return self;
+}
+
+- (void)main {
+ DCHECK(task_) << "-[TaskOperation main] called with no task";
+ task_->Run();
+ delete task_;
+ task_ = NULL;
+}
+
+- (void)dealloc {
+ DCHECK(!task_) << "-[TaskOperation dealloc] called on unused TaskOperation";
+ delete task_;
+ [super dealloc];
+}
+
+@end
+
+bool WorkerPool::PostTask(const tracked_objects::Location& from_here,
+ Task* task, bool task_is_slow) {
+ // Ignore |task_is_slow|, it doesn't map directly to any tunable aspect of
+ // an NSOperation.
+
+ task->SetBirthPlace(from_here);
+
+ NSOperationQueue* operation_queue = SingletonObjC<NSOperationQueue>::get();
+ [operation_queue addOperation:[TaskOperation taskOperationWithTask:task]];
+
+ return true;
+}