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

Side by Side Diff: src/core/SkTaskGroup.h

Issue 689673003: SkTaskGroup::batch(fn, args, N) (Closed) Base URL: https://skia.googlesource.com/skia.git@master
Patch Set: pun fn pointers Created 6 years, 1 month 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
« no previous file with comments | « src/core/SkMultiPictureDraw.cpp ('k') | src/core/SkTaskGroup.cpp » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
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 12
13 struct SkRunnable; 13 struct SkRunnable;
14 14
15 class SkTaskGroup : SkNoncopyable { 15 class SkTaskGroup : SkNoncopyable {
16 public: 16 public:
17 // Create one of these in main() to enable SkTaskGroups globally. 17 // Create one of these in main() to enable SkTaskGroups globally.
18 struct Enabler : SkNoncopyable { 18 struct Enabler : SkNoncopyable {
19 explicit Enabler(int threads = -1); // Default is system-reported core count. 19 explicit Enabler(int threads = -1); // Default is system-reported core count.
20 ~Enabler(); 20 ~Enabler();
21 }; 21 };
22 22
23 SkTaskGroup(); 23 SkTaskGroup();
24 ~SkTaskGroup() { this->wait(); } 24 ~SkTaskGroup() { this->wait(); }
25 25
26 // Add a task to this SkTaskGroup. It will likely run on another thread. 26 // Add a task to this SkTaskGroup. It will likely run on another thread.
27 // Neither add() method takes owership of any of its parameters. 27 // Neither add() method takes owership of any of its parameters.
28 void add(SkRunnable*); 28 void add(SkRunnable*);
29 void add(void (*fn)(void*), void* arg); 29
30 template <typename T>
31 void add(void (*fn)(T*), T* arg) { this->add((void_fn)fn, (void*)arg); }
32
33 // Add a batch of N tasks, all calling fn with different arguments.
34 // Equivalent to a loop over add(fn, arg), but with perhaps less synchroniza tion overhead.
35 template <typename T>
36 void batch(void (*fn)(T*), T* args, int N) { this->batch((void_fn)fn, args, N, sizeof(T)); }
30 37
31 // Block until all Tasks previously add()ed to this SkTaskGroup have run. 38 // Block until all Tasks previously add()ed to this SkTaskGroup have run.
32 // You may safely reuse this SkTaskGroup after wait() returns. 39 // You may safely reuse this SkTaskGroup after wait() returns.
33 void wait(); 40 void wait();
34 41
35 private: 42 private:
43 typedef void(*void_fn)(void*);
44
45 void add (void_fn, void* arg);
46 void batch(void_fn, void* args, int N, size_t stride);
47
36 /*atomic*/ int32_t fPending; 48 /*atomic*/ int32_t fPending;
37 }; 49 };
38 50
39 #endif//SkTaskGroup_DEFINED 51 #endif//SkTaskGroup_DEFINED
OLDNEW
« no previous file with comments | « src/core/SkMultiPictureDraw.cpp ('k') | src/core/SkTaskGroup.cpp » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698