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

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

Issue 11547006: De-flake the LibDispatchTaskRunner tests. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Remove circular reference 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
1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. 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 2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file. 3 // found in the LICENSE file.
4 4
5 #include "base/mac/libdispatch_task_runner.h" 5 #include "base/mac/libdispatch_task_runner.h"
6 6
7 #include "base/callback.h" 7 #include "base/callback.h"
8 8
9 namespace base { 9 namespace base {
10 namespace mac { 10 namespace mac {
11 11
12 LibDispatchTaskRunner::LibDispatchTaskRunner(const char* name) 12 LibDispatchTaskRunner::LibDispatchTaskRunner(const char* name)
13 : queue_(dispatch_queue_create(name, NULL)) { 13 : queue_(dispatch_queue_create(name, NULL)),
14 queue_finalized_(false, false) {
15 dispatch_set_context(queue_, this);
16 dispatch_set_finalizer_f(queue_, &LibDispatchTaskRunner::Finalizer);
14 } 17 }
15 18
16 bool LibDispatchTaskRunner::PostDelayedTask( 19 bool LibDispatchTaskRunner::PostDelayedTask(
17 const tracked_objects::Location& from_here, 20 const tracked_objects::Location& from_here,
18 const Closure& task, 21 const Closure& task,
19 base::TimeDelta delay) { 22 base::TimeDelta delay) {
20 if (!queue_) 23 if (!queue_)
21 return false; 24 return false;
22 25
23 // The block runtime would implicitly copy the reference, not the object 26 // The block runtime would implicitly copy the reference, not the object
(...skipping 19 matching lines...) Expand all
43 return queue_ == dispatch_get_current_queue(); 46 return queue_ == dispatch_get_current_queue();
44 } 47 }
45 48
46 bool LibDispatchTaskRunner::PostNonNestableDelayedTask( 49 bool LibDispatchTaskRunner::PostNonNestableDelayedTask(
47 const tracked_objects::Location& from_here, 50 const tracked_objects::Location& from_here,
48 const Closure& task, 51 const Closure& task,
49 base::TimeDelta delay) { 52 base::TimeDelta delay) {
50 return PostDelayedTask(from_here, task, delay); 53 return PostDelayedTask(from_here, task, delay);
51 } 54 }
52 55
56 void LibDispatchTaskRunner::Shutdown() {
57 dispatch_release(queue_);
58 queue_ = NULL;
59 queue_finalized_.Wait();
60 }
61
53 dispatch_queue_t LibDispatchTaskRunner::GetDispatchQueue() const { 62 dispatch_queue_t LibDispatchTaskRunner::GetDispatchQueue() const {
54 return queue_; 63 return queue_;
55 } 64 }
56 65
57 LibDispatchTaskRunner::~LibDispatchTaskRunner() { 66 LibDispatchTaskRunner::~LibDispatchTaskRunner() {
58 dispatch_release(queue_); 67 if (queue_) {
68 dispatch_set_context(queue_, NULL);
69 dispatch_set_finalizer_f(queue_, NULL);
70 dispatch_release(queue_);
71 }
72 }
73
74 void LibDispatchTaskRunner::Finalizer(void* context) {
75 LibDispatchTaskRunner* self = static_cast<LibDispatchTaskRunner*>(context);
76 self->queue_finalized_.Signal();
59 } 77 }
60 78
61 } // namespace mac 79 } // namespace mac
62 } // namespace base 80 } // 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