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

#include <SkOnce.h>

Public Member Functions

constexpr SkOnce ()=default
 
template<typename Fn , typename... Args>
void operator() (Fn &&fn, Args &&... args)
 

Detailed Description

Definition at line 22 of file SkOnce.h.

Constructor & Destructor Documentation

◆ SkOnce()

constexpr SkOnce::SkOnce ( )
constexprdefault

Member Function Documentation

◆ operator()()

template<typename Fn , typename... Args>
void SkOnce::operator() ( Fn &&  fn,
Args &&...  args 
)
inline

Definition at line 27 of file SkOnce.h.

27 {
28 auto state = fState.load(std::memory_order_acquire);
29
30 if (state == Done) {
31 return;
32 }
33
34 // If it looks like no one has started calling fn(), try to claim that job.
35 if (state == NotStarted && fState.compare_exchange_strong(state, Claimed,
36 std::memory_order_relaxed,
37 std::memory_order_relaxed)) {
38 // Great! We'll run fn() then notify the other threads by releasing Done into fState.
39 fn(std::forward<Args>(args)...);
40 return fState.store(Done, std::memory_order_release);
41 }
42
43 // Some other thread is calling fn().
44 // We'll just spin here acquiring until it releases Done into fState.
46 while (fState.load(std::memory_order_acquire) != Done) { /*spin*/ }
48 }
#define SK_POTENTIALLY_BLOCKING_REGION_END
#define SK_POTENTIALLY_BLOCKING_REGION_BEGIN
AtkStateType state
G_BEGIN_DECLS G_MODULE_EXPORT FlValue * args

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