| OLD | NEW |
| 1 /* | 1 /* |
| 2 * Copyright 2014 Google Inc. | 2 * Copyright 2014 Google Inc. |
| 3 * | 3 * |
| 4 * Use of this source code is governed by a BSD-style license that can be | 4 * Use of this source code is governed by a BSD-style license that can be |
| 5 * found in the LICENSE file. | 5 * found in the LICENSE file. |
| 6 */ | 6 */ |
| 7 | 7 |
| 8 #ifndef SkTaskGroup_DEFINED | 8 #ifndef SkTaskGroup_DEFINED |
| 9 #define SkTaskGroup_DEFINED | 9 #define SkTaskGroup_DEFINED |
| 10 | 10 |
| 11 #include <functional> | 11 #include <functional> |
| 12 | 12 |
| 13 #include "SkTypes.h" | 13 #include "SkTypes.h" |
| 14 #include "SkAtomics.h" | 14 #include "SkAtomics.h" |
| 15 #include "SkTemplates.h" | 15 #include "SkTemplates.h" |
| 16 | 16 |
| 17 struct SkRunnable; | |
| 18 | |
| 19 class SkTaskGroup : SkNoncopyable { | 17 class SkTaskGroup : SkNoncopyable { |
| 20 public: | 18 public: |
| 21 // Create one of these in main() to enable SkTaskGroups globally. | 19 // Create one of these in main() to enable SkTaskGroups globally. |
| 22 struct Enabler : SkNoncopyable { | 20 struct Enabler : SkNoncopyable { |
| 23 explicit Enabler(int threads = -1); // Default is system-reported core
count. | 21 explicit Enabler(int threads = -1); // Default is system-reported core
count. |
| 24 ~Enabler(); | 22 ~Enabler(); |
| 25 }; | 23 }; |
| 26 | 24 |
| 27 SkTaskGroup(); | 25 SkTaskGroup(); |
| 28 ~SkTaskGroup() { this->wait(); } | 26 ~SkTaskGroup() { this->wait(); } |
| 29 | 27 |
| 30 // Add a task to this SkTaskGroup. It will likely run on another thread. | 28 // Add a task to this SkTaskGroup. It will likely run on another thread. |
| 31 // Neither add() method takes owership of any of its parameters. | |
| 32 void add(SkRunnable*); | |
| 33 | |
| 34 void add(std::function<void(void)> fn); | 29 void add(std::function<void(void)> fn); |
| 35 | 30 |
| 36 // Add a batch of N tasks, all calling fn with different arguments. | 31 // Add a batch of N tasks, all calling fn with different arguments. |
| 37 void batch(int N, std::function<void(int)> fn); | 32 void batch(int N, std::function<void(int)> fn); |
| 38 | 33 |
| 39 // Block until all Tasks previously add()ed to this SkTaskGroup have run. | 34 // Block until all Tasks previously add()ed to this SkTaskGroup have run. |
| 40 // You may safely reuse this SkTaskGroup after wait() returns. | 35 // You may safely reuse this SkTaskGroup after wait() returns. |
| 41 void wait(); | 36 void wait(); |
| 42 | 37 |
| 43 private: | 38 private: |
| 44 SkAtomic<int32_t> fPending; | 39 SkAtomic<int32_t> fPending; |
| 45 }; | 40 }; |
| 46 | 41 |
| 47 // Returns best estimate of number of CPU cores available to use. | 42 // Returns best estimate of number of CPU cores available to use. |
| 48 int sk_num_cores(); | 43 int sk_num_cores(); |
| 49 | 44 |
| 50 #endif//SkTaskGroup_DEFINED | 45 #endif//SkTaskGroup_DEFINED |
| OLD | NEW |