ipc/chromium/src/base/worker_pool_mac.mm

Wed, 31 Dec 2014 06:09:35 +0100

author
Michael Schloh von Bennewitz <michael@schloh.com>
date
Wed, 31 Dec 2014 06:09:35 +0100
changeset 0
6474c204b198
permissions
-rw-r--r--

Cloned upstream origin tor-browser at tor-browser-31.3.0esr-4.5-1-build1
revision ID fc1c9ff7c1b2defdbc039f12214767608f46423f for hacking purpose.

michael@0 1 // Copyright (c) 2008 The Chromium Authors. All rights reserved.
michael@0 2 // Use of this source code is governed by a BSD-style license that can be
michael@0 3 // found in the LICENSE file.
michael@0 4
michael@0 5 #include "base/worker_pool.h"
michael@0 6
michael@0 7 #import <Foundation/Foundation.h>
michael@0 8
michael@0 9 #include "base/logging.h"
michael@0 10 #import "base/singleton_objc.h"
michael@0 11 #include "base/task.h"
michael@0 12
michael@0 13 // TaskOperation adapts Task->Run() for use in an NSOperationQueue.
michael@0 14 @interface TaskOperation : NSOperation {
michael@0 15 @private
michael@0 16 Task* task_; // (strong)
michael@0 17 }
michael@0 18
michael@0 19 // Returns an autoreleased instance of TaskOperation. See -initWithTask: for
michael@0 20 // details.
michael@0 21 + (id)taskOperationWithTask:(Task*)task;
michael@0 22
michael@0 23 // Designated initializer. |task| is adopted as the Task* whose Run method
michael@0 24 // this operation will call when executed.
michael@0 25 - (id)initWithTask:(Task*)task;
michael@0 26
michael@0 27 @end
michael@0 28
michael@0 29 @implementation TaskOperation
michael@0 30
michael@0 31 + (id)taskOperationWithTask:(Task*)task {
michael@0 32 return [[[TaskOperation alloc] initWithTask:task] autorelease];
michael@0 33 }
michael@0 34
michael@0 35 - (id)init {
michael@0 36 return [self initWithTask:NULL];
michael@0 37 }
michael@0 38
michael@0 39 - (id)initWithTask:(Task*)task {
michael@0 40 if ((self = [super init])) {
michael@0 41 task_ = task;
michael@0 42 }
michael@0 43 return self;
michael@0 44 }
michael@0 45
michael@0 46 - (void)main {
michael@0 47 DCHECK(task_) << "-[TaskOperation main] called with no task";
michael@0 48 task_->Run();
michael@0 49 delete task_;
michael@0 50 task_ = NULL;
michael@0 51 }
michael@0 52
michael@0 53 - (void)dealloc {
michael@0 54 DCHECK(!task_) << "-[TaskOperation dealloc] called on unused TaskOperation";
michael@0 55 delete task_;
michael@0 56 [super dealloc];
michael@0 57 }
michael@0 58
michael@0 59 @end
michael@0 60
michael@0 61 bool WorkerPool::PostTask(const tracked_objects::Location& from_here,
michael@0 62 Task* task, bool task_is_slow) {
michael@0 63 // Ignore |task_is_slow|, it doesn't map directly to any tunable aspect of
michael@0 64 // an NSOperation.
michael@0 65
michael@0 66 task->SetBirthPlace(from_here);
michael@0 67
michael@0 68 NSOperationQueue* operation_queue = SingletonObjC<NSOperationQueue>::get();
michael@0 69 [operation_queue addOperation:[TaskOperation taskOperationWithTask:task]];
michael@0 70
michael@0 71 return true;
michael@0 72 }

mercurial