ipc/chromium/src/base/worker_pool_mac.mm

changeset 0
6474c204b198
     1.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
     1.2 +++ b/ipc/chromium/src/base/worker_pool_mac.mm	Wed Dec 31 06:09:35 2014 +0100
     1.3 @@ -0,0 +1,72 @@
     1.4 +// Copyright (c) 2008 The Chromium Authors. All rights reserved.
     1.5 +// Use of this source code is governed by a BSD-style license that can be
     1.6 +// found in the LICENSE file.
     1.7 +
     1.8 +#include "base/worker_pool.h"
     1.9 +
    1.10 +#import <Foundation/Foundation.h>
    1.11 +
    1.12 +#include "base/logging.h"
    1.13 +#import "base/singleton_objc.h"
    1.14 +#include "base/task.h"
    1.15 +
    1.16 +// TaskOperation adapts Task->Run() for use in an NSOperationQueue.
    1.17 +@interface TaskOperation : NSOperation {
    1.18 + @private
    1.19 +  Task* task_;  // (strong)
    1.20 +}
    1.21 +
    1.22 +// Returns an autoreleased instance of TaskOperation.  See -initWithTask: for
    1.23 +// details.
    1.24 ++ (id)taskOperationWithTask:(Task*)task;
    1.25 +
    1.26 +// Designated initializer.  |task| is adopted as the Task* whose Run method
    1.27 +// this operation will call when executed.
    1.28 +- (id)initWithTask:(Task*)task;
    1.29 +
    1.30 +@end
    1.31 +
    1.32 +@implementation TaskOperation
    1.33 +
    1.34 ++ (id)taskOperationWithTask:(Task*)task {
    1.35 +  return [[[TaskOperation alloc] initWithTask:task] autorelease];
    1.36 +}
    1.37 +
    1.38 +- (id)init {
    1.39 +  return [self initWithTask:NULL];
    1.40 +}
    1.41 +
    1.42 +- (id)initWithTask:(Task*)task {
    1.43 +  if ((self = [super init])) {
    1.44 +    task_ = task;
    1.45 +  }
    1.46 +  return self;
    1.47 +}
    1.48 +
    1.49 +- (void)main {
    1.50 +  DCHECK(task_) << "-[TaskOperation main] called with no task";
    1.51 +  task_->Run();
    1.52 +  delete task_;
    1.53 +  task_ = NULL;
    1.54 +}
    1.55 +
    1.56 +- (void)dealloc {
    1.57 +  DCHECK(!task_) << "-[TaskOperation dealloc] called on unused TaskOperation";
    1.58 +  delete task_;
    1.59 +  [super dealloc];
    1.60 +}
    1.61 +
    1.62 +@end
    1.63 +
    1.64 +bool WorkerPool::PostTask(const tracked_objects::Location& from_here,
    1.65 +                          Task* task, bool task_is_slow) {
    1.66 +  // Ignore |task_is_slow|, it doesn't map directly to any tunable aspect of
    1.67 +  // an NSOperation.
    1.68 +
    1.69 +  task->SetBirthPlace(from_here);
    1.70 +
    1.71 +  NSOperationQueue* operation_queue = SingletonObjC<NSOperationQueue>::get();
    1.72 +  [operation_queue addOperation:[TaskOperation taskOperationWithTask:task]];
    1.73 +
    1.74 +  return true;
    1.75 +}

mercurial