Chromium Code Reviews| 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 "SkTypes.h" | 11 #include "SkTypes.h" |
| 12 #include "SkRunnable.h" | 12 #include "SkRunnable.h" |
| 13 | 13 |
| 14 class SkTaskGroup : SkNoncopyable { | 14 class SkTaskGroup : SkNoncopyable { |
| 15 public: | 15 public: |
| 16 // Create one of these in main() to enable SkTaskGroups globally. | 16 // Create one of these in main() to enable SkTaskGroups globally. |
| 17 struct Enabler : SkNoncopyable { | 17 struct Enabler : SkNoncopyable { |
| 18 explicit Enabler(int threads = -1); // Default is system-reported core count. | 18 explicit Enabler(int threads = -1); // Default is system-reported core count. |
| 19 ~Enabler(); | 19 ~Enabler(); |
| 20 }; | 20 }; |
| 21 | 21 |
| 22 SkTaskGroup(); | 22 SkTaskGroup(); |
| 23 ~SkTaskGroup() { this->wait(); } | 23 ~SkTaskGroup() { this->wait(); } |
| 24 | 24 |
| 25 // Add a task to this SkTaskGroup. It will likely run on another thread. | 25 // Add a task to this SkTaskGroup. It will likely run on another thread. |
| 26 // Neither add() method takes owership of any of its parameters. | 26 // Neither add() method takes owership of any of its parameters. |
| 27 void add(SkRunnable*); | 27 void add(SkRunnable*); |
| 28 void add(void (*fn)(void*), void* arg); | 28 void add(void (*fn)(void*), void* arg); |
| 29 | 29 |
| 30 // Add a batch of N tasks, all calling fn with different arguments. | |
| 31 // Equivalent to a loop over add(fn, arg), but with perhaps less synchroniza tion overhead. | |
| 32 template <typename T> | |
| 33 void batch(void (*fn)(void*), T* args, int N) { this->batch(fn, args, N, siz eof(T)); } | |
|
reed1
2014/10/29 19:57:30
1. Slightly odd to me that we don't expose the non
mtklein
2014/10/29 20:01:00
Yeah. Just seemed like the template version makes
| |
| 34 | |
| 30 // Block until all Tasks previously add()ed to this SkTaskGroup have run. | 35 // Block until all Tasks previously add()ed to this SkTaskGroup have run. |
| 31 // You may safely reuse this SkTaskGroup after wait() returns. | 36 // You may safely reuse this SkTaskGroup after wait() returns. |
| 32 void wait(); | 37 void wait(); |
| 33 | 38 |
| 34 private: | 39 private: |
| 40 void batch(void (*fn)(void*), void* args, int N, size_t stride); | |
| 41 | |
| 35 /*atomic*/ int32_t fPending; | 42 /*atomic*/ int32_t fPending; |
| 36 }; | 43 }; |
| 37 | 44 |
| 38 #endif//SkTaskGroup_DEFINED | 45 #endif//SkTaskGroup_DEFINED |
| OLD | NEW |