Flutter Engine
The Flutter Engine
Loading...
Searching...
No Matches
Classes | Public Member Functions | List of all members
SkTaskGroup Class Reference

#include <SkTaskGroup.h>

Inheritance diagram for SkTaskGroup:
SkNoncopyable

Classes

struct  Enabler
 

Public Member Functions

 SkTaskGroup (SkExecutor &executor=SkExecutor::GetDefault())
 
 ~SkTaskGroup ()
 
void add (std::function< void(void)> fn)
 
void batch (int N, std::function< void(int)> fn)
 
bool done () const
 
void wait ()
 

Detailed Description

Definition at line 20 of file SkTaskGroup.h.

Constructor & Destructor Documentation

◆ SkTaskGroup()

SkTaskGroup::SkTaskGroup ( SkExecutor executor = SkExecutor::GetDefault())
explicit

Definition at line 14 of file SkTaskGroup.cpp.

14: fPending(0), fExecutor(executor) {}

◆ ~SkTaskGroup()

SkTaskGroup::~SkTaskGroup ( )
inline

Definition at line 24 of file SkTaskGroup.h.

24{ this->wait(); }

Member Function Documentation

◆ add()

void SkTaskGroup::add ( std::function< void(void)>  fn)

Definition at line 16 of file SkTaskGroup.cpp.

16 {
17 fPending.fetch_add(+1, std::memory_order_relaxed);
18 fExecutor.add([this, fn{std::move(fn)}] {
19 fn();
20 fPending.fetch_add(-1, std::memory_order_release);
21 });
22}
virtual void add(std::function< void(void)>)=0

◆ batch()

void SkTaskGroup::batch ( int  N,
std::function< void(int)>  fn 
)

Definition at line 24 of file SkTaskGroup.cpp.

24 {
25 // TODO: I really thought we had some sort of more clever chunking logic.
26 fPending.fetch_add(+N, std::memory_order_relaxed);
27 for (int i = 0; i < N; i++) {
28 fExecutor.add([fn, i, this] {
29 fn(i);
30 fPending.fetch_add(-1, std::memory_order_release);
31 });
32 }
33}
#define N
Definition beziers.cpp:19

◆ done()

bool SkTaskGroup::done ( ) const

Definition at line 35 of file SkTaskGroup.cpp.

35 {
36 return fPending.load(std::memory_order_acquire) == 0;
37}

◆ wait()

void SkTaskGroup::wait ( )

Definition at line 39 of file SkTaskGroup.cpp.

39 {
40 // Actively help the executor do work until our task group is done.
41 // This lets SkTaskGroups nest arbitrarily deep on a single SkExecutor:
42 // no thread ever blocks waiting for others to do its work.
43 // (We may end up doing work that's not part of our task group. That's fine.)
44 while (!this->done()) {
45 fExecutor.borrow();
46 }
47}
virtual void borrow()
Definition SkExecutor.h:33
bool done() const

The documentation for this class was generated from the following files: