Chromium Code Reviews| OLD | NEW |
|---|---|
| (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 #ifndef BASE_MAC_LIBDISPATCH_SEQUENCED_TASK_RUNNER_H_ | |
| 6 #define BASE_MAC_LIBDISPATCH_SEQUENCED_TASK_RUNNER_H_ | |
| 7 | |
| 8 #include <dispatch/dispatch.h> | |
| 9 | |
| 10 #include "base/single_thread_task_runner.h" | |
| 11 | |
| 12 namespace base { | |
| 13 namespace mac { | |
| 14 | |
| 15 // This is an implementation of the TaskRunner interface that runs closures on | |
| 16 // a thread managed by Apple's libdispatch. This has the benefit of being able | |
| 17 // to PostTask() and friends to a dispatch queue, while being reusable as a | |
| 18 // dispatch_queue_t. | |
| 19 // | |
| 20 // One would use this class if an object lives exclusively on one thread but | |
| 21 // needs a dispatch_queue_t for use in a system API. This ensures all dispatch | |
| 22 // callbacks happen on the same thread as Closure tasks. | |
| 23 // | |
| 24 // A LibDispatchTaskRunner will continue to run until all references to the | |
| 25 // underlying dispatch queue are released. | |
| 26 // | |
| 27 // Important Notes: | |
| 28 // - There is no MessageLoop running on this thread, and ::current() returns | |
| 29 // NULL. | |
| 30 // - No nested loops can be run, and all tasks are run non-nested. | |
| 31 // - Work scheduled via libdispatch runs at the same priority as and is | |
| 32 // interleaved with posted tasks, though FIFO order is guaranteed. | |
| 33 // | |
| 34 class LibDispatchTaskRunner : public base::SingleThreadTaskRunner { | |
| 35 public: | |
| 36 // Starts a new serial dispatch queue with a given name. | |
| 37 explicit LibDispatchTaskRunner(const char* name); | |
|
Mark Mentovai
2012/12/06 22:11:45
Dunno if it’s totally useful to have callers suppl
Robert Sesek
2012/12/06 22:18:05
No, callers should supply it like they do for well
| |
| 38 | |
| 39 // base::TaskRunner: | |
| 40 virtual bool PostDelayedTask(const tracked_objects::Location& from_here, | |
| 41 const Closure& task, | |
| 42 base::TimeDelta delay) OVERRIDE; | |
| 43 virtual bool RunsTasksOnCurrentThread() const OVERRIDE; | |
| 44 | |
| 45 // base::SequencedTaskRunner: | |
| 46 virtual bool PostNonNestableDelayedTask( | |
| 47 const tracked_objects::Location& from_here, | |
| 48 const Closure& task, | |
| 49 base::TimeDelta delay) OVERRIDE; | |
| 50 | |
| 51 // Returns the dispatch queue associated with this task runner, for use with | |
| 52 // system APIs that take dispatch queues. The caller is responsible for | |
| 53 // retaining the result. | |
| 54 dispatch_queue_t GetDispatchQueue() const; | |
| 55 | |
| 56 protected: | |
| 57 virtual ~LibDispatchTaskRunner(); | |
| 58 | |
| 59 private: | |
| 60 dispatch_queue_t queue_; | |
| 61 }; | |
| 62 | |
| 63 } // namespace mac | |
| 64 } // namespace base | |
| 65 | |
| 66 #endif // BASE_MAC_LIBDISPATCH_SEQUENCED_TASK_RUNNER_H_ | |
| OLD | NEW |