Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(410)

Side by Side Diff: base/mac/libdispatch_task_runner.cc

Issue 11464009: Create LibDispatchTaskRunner, a SingleThreadTaskRunner that is backed by a libdispatch queue. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: BASE_EXPORT Created 8 years ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch | Annotate | Revision Log
« no previous file with comments | « base/mac/libdispatch_task_runner.h ('k') | base/mac/libdispatch_task_runner_unittest.cc » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
(Empty)
1 // Copyright (c) 2012 The Chromium Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file.
4
5 #include "base/mac/libdispatch_task_runner.h"
6
7 #include "base/callback.h"
8
9 namespace base {
10 namespace mac {
11
12 LibDispatchTaskRunner::LibDispatchTaskRunner(const char* name)
13 : queue_(dispatch_queue_create(name, NULL)) {
14 }
15
16 bool LibDispatchTaskRunner::PostDelayedTask(
17 const tracked_objects::Location& from_here,
18 const Closure& task,
19 base::TimeDelta delay) {
20 if (!queue_)
21 return false;
22
23 // The block runtime would implicitly copy the reference, not the object
24 // it's referencing. Copy the closure into block storage so it's available
25 // to run.
26 __block const Closure task_copy = task;
27 void(^run_task)(void) = ^{
28 task_copy.Run();
29 };
30
31 int64 delay_nano =
32 delay.InMicroseconds() * base::Time::kNanosecondsPerMicrosecond;
33 if (delay_nano > 0) {
34 dispatch_time_t time = dispatch_time(DISPATCH_TIME_NOW, delay_nano);
35 dispatch_after(time, queue_, run_task);
36 } else {
37 dispatch_async(queue_, run_task);
38 }
39 return true;
40 }
41
42 bool LibDispatchTaskRunner::RunsTasksOnCurrentThread() const {
43 return queue_ == dispatch_get_current_queue();
44 }
45
46 bool LibDispatchTaskRunner::PostNonNestableDelayedTask(
47 const tracked_objects::Location& from_here,
48 const Closure& task,
49 base::TimeDelta delay) {
50 return PostDelayedTask(from_here, task, delay);
51 }
52
53 dispatch_queue_t LibDispatchTaskRunner::GetDispatchQueue() const {
54 return queue_;
55 }
56
57 LibDispatchTaskRunner::~LibDispatchTaskRunner() {
58 dispatch_release(queue_);
59 }
60
61 } // namespace mac
62 } // namespace base
OLDNEW
« no previous file with comments | « base/mac/libdispatch_task_runner.h ('k') | base/mac/libdispatch_task_runner_unittest.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698