Flutter Engine
The Flutter Engine
Loading...
Searching...
No Matches
Public Member Functions | List of all members
SkThreadPool< WorkList > Class Template Referencefinal
Inheritance diagram for SkThreadPool< WorkList >:
SkExecutor

Public Member Functions

 SkThreadPool (int threads, bool allowBorrowing)
 
 ~SkThreadPool () override
 
void add (std::function< void(void)> work) override
 
void borrow () override
 
- Public Member Functions inherited from SkExecutor
virtual ~SkExecutor ()
 

Additional Inherited Members

- Static Public Member Functions inherited from SkExecutor
static std::unique_ptr< SkExecutorMakeFIFOThreadPool (int threads=0, bool allowBorrowing=true)
 
static std::unique_ptr< SkExecutorMakeLIFOThreadPool (int threads=0, bool allowBorrowing=true)
 
static SkExecutorGetDefault ()
 
static void SetDefault (SkExecutor *)
 
- Protected Member Functions inherited from SkExecutor
 SkExecutor ()=default
 
 SkExecutor (const SkExecutor &)=delete
 
SkExecutoroperator= (const SkExecutor &)=delete
 

Detailed Description

template<typename WorkList>
class SkThreadPool< WorkList >

Definition at line 75 of file SkExecutor.cpp.

Constructor & Destructor Documentation

◆ SkThreadPool()

template<typename WorkList >
SkThreadPool< WorkList >::SkThreadPool ( int  threads,
bool  allowBorrowing 
)
inlineexplicit

Definition at line 77 of file SkExecutor.cpp.

77 : fAllowBorrowing(allowBorrowing) {
78 for (int i = 0; i < threads; i++) {
79 fThreads.emplace_back(&Loop, this);
80 }
81 }
T & emplace_back(Args &&... args)
Definition SkTArray.h:243

◆ ~SkThreadPool()

template<typename WorkList >
SkThreadPool< WorkList >::~SkThreadPool ( )
inlineoverride

Definition at line 83 of file SkExecutor.cpp.

83 {
84 // Signal each thread that it's time to shut down.
85 for (int i = 0; i < fThreads.size(); i++) {
86 this->add(nullptr);
87 }
88 // Wait for each thread to shut down.
89 for (int i = 0; i < fThreads.size(); i++) {
90 fThreads[i].join();
91 }
92 }
void add(std::function< void(void)> work) override
int size() const
Definition SkTArray.h:416

Member Function Documentation

◆ add()

template<typename WorkList >
void SkThreadPool< WorkList >::add ( std::function< void(void)>  work)
inlineoverridevirtual

Implements SkExecutor.

Definition at line 94 of file SkExecutor.cpp.

94 {
95 // Add some work to our pile of work to do.
96 {
97 SkAutoMutexExclusive lock(fWorkLock);
98 fWork.emplace_back(std::move(work));
99 }
100 // Tell the Loop() threads to pick it up.
101 fWorkAvailable.signal(1);
102 }
void signal(int n=1)
Definition SkSemaphore.h:56

◆ borrow()

template<typename WorkList >
void SkThreadPool< WorkList >::borrow ( )
inlineoverridevirtual

Reimplemented from SkExecutor.

Definition at line 104 of file SkExecutor.cpp.

104 {
105 // If there is work waiting and we're allowed to borrow work, do it.
106 if (fAllowBorrowing && fWorkAvailable.try_wait()) {
107 SkAssertResult(this->do_work());
108 }
109 }
#define SkAssertResult(cond)
Definition SkAssert.h:123
SK_SPI bool try_wait()

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