Flutter Engine
The Flutter Engine
SkTaskGroup.h
Go to the documentation of this file.
1/*
2 * Copyright 2014 Google Inc.
3 *
4 * Use of this source code is governed by a BSD-style license that can be
5 * found in the LICENSE file.
6 */
7
8#ifndef SkTaskGroup_DEFINED
9#define SkTaskGroup_DEFINED
10
14
15#include <atomic>
16#include <cstdint>
17#include <functional>
18#include <memory>
19
21public:
22 // Tasks added to this SkTaskGroup will run on its executor.
23 explicit SkTaskGroup(SkExecutor& executor = SkExecutor::GetDefault());
24 ~SkTaskGroup() { this->wait(); }
25
26 // Add a task to this SkTaskGroup.
27 void add(std::function<void(void)> fn);
28
29 // Add a batch of N tasks, all calling fn with different arguments.
30 void batch(int N, std::function<void(int)> fn);
31
32 // Returns true if all Tasks previously add()ed to this SkTaskGroup have run.
33 // It is safe to reuse this SkTaskGroup once done().
34 bool done() const;
35
36 // Block until done().
37 void wait();
38
39 // A convenience for testing tools.
40 // Creates and owns a thread pool, and passes it to SkExecutor::SetDefault().
41 struct Enabler {
42 explicit Enabler(int threads = -1); // -1 -> num_cores, 0 -> noop
43 std::unique_ptr<SkExecutor> fThreadPool;
44 };
45
46private:
47 std::atomic<int32_t> fPending;
48 SkExecutor& fExecutor;
49};
50
51#endif//SkTaskGroup_DEFINED
#define N
Definition: beziers.cpp:19
static SkExecutor & GetDefault()
Definition: SkExecutor.cpp:50
SkTaskGroup(SkExecutor &executor=SkExecutor::GetDefault())
Definition: SkTaskGroup.cpp:14
void batch(int N, std::function< void(int)> fn)
Definition: SkTaskGroup.cpp:24
void add(std::function< void(void)> fn)
Definition: SkTaskGroup.cpp:16
bool done() const
Definition: SkTaskGroup.cpp:35
Dart_NativeFunction function
Definition: fuchsia.cc:51
Enabler(int threads=-1)
Definition: SkTaskGroup.cpp:49
std::unique_ptr< SkExecutor > fThreadPool
Definition: SkTaskGroup.h:43