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

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

Issue 1733323002: Clean up EGL thread state at thread exit in nanobench and DM (Closed) Base URL: https://skia.googlesource.com/skia.git@master
Patch Set: fix main thread usage also Created 4 years, 10 months 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 | « include/gpu/gl/command_buffer/SkCommandBufferGLContext.h ('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 <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 class SkTaskGroup : SkNoncopyable { 17 class SkTaskGroup : SkNoncopyable {
18 public: 18 public:
19 // Create one of these in main() to enable SkTaskGroups globally. 19 // Create one of these in main() to enable SkTaskGroups globally.
20 struct Enabler : SkNoncopyable { 20 struct Enabler : SkNoncopyable {
21 explicit Enabler(int threads = -1); // Default is system-reported core count. 21 // @param threads Default is system-reported core count.
22 // @param cleanupFn Function to call in each thread that may have
23 // scheduled SkTaskGroup tasks.
24 explicit Enabler(int threads = -1, std::function<void(void)> cleanupFn = nullptr);
22 ~Enabler(); 25 ~Enabler();
26 private:
27 std::function<void(void)> fCleanupFn;
23 }; 28 };
24 29
25 SkTaskGroup(); 30 SkTaskGroup();
26 ~SkTaskGroup() { this->wait(); } 31 ~SkTaskGroup() { this->wait(); }
27 32
28 // Add a task to this SkTaskGroup. It will likely run on another thread. 33 // Add a task to this SkTaskGroup. It will likely run on another thread.
29 void add(std::function<void(void)> fn); 34 void add(std::function<void(void)> fn);
30 35
31 // Add a batch of N tasks, all calling fn with different arguments. 36 // Add a batch of N tasks, all calling fn with different arguments.
32 void batch(int N, std::function<void(int)> fn); 37 void batch(int N, std::function<void(int)> fn);
33 38
34 // Block until all Tasks previously add()ed to this SkTaskGroup have run. 39 // Block until all Tasks previously add()ed to this SkTaskGroup have run.
35 // You may safely reuse this SkTaskGroup after wait() returns. 40 // You may safely reuse this SkTaskGroup after wait() returns.
36 void wait(); 41 void wait();
37 42
38 private: 43 private:
39 SkAtomic<int32_t> fPending; 44 SkAtomic<int32_t> fPending;
40 }; 45 };
41 46
42 // Returns best estimate of number of CPU cores available to use. 47 // Returns best estimate of number of CPU cores available to use.
43 int sk_num_cores(); 48 int sk_num_cores();
44 49
45 #endif//SkTaskGroup_DEFINED 50 #endif//SkTaskGroup_DEFINED
OLDNEW
« no previous file with comments | « include/gpu/gl/command_buffer/SkCommandBufferGLContext.h ('k') | src/core/SkTaskGroup.cpp » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698