Flutter Engine
fml::SyncSwitch Class Reference

#include <sync_switch.h>

Classes

struct  Handlers
 Represents the 2 code paths available when calling |SyncSwitch::Execute|. More...
 

Public Member Functions

 SyncSwitch (bool value=false)
 
void Execute (const Handlers &handlers) const
 
void SetSwitch (bool value)
 

Detailed Description

A threadsafe structure that allows you to switch between 2 different execution paths.

Execution and setting the switch is exclusive, i.e. only one will happen at a time.

Definition at line 21 of file sync_switch.h.

Constructor & Destructor Documentation

◆ SyncSwitch()

fml::SyncSwitch::SyncSwitch ( bool  value = false)
explicit

Create a |SyncSwitch| with the specified value.

Parameters
[in]valueDefault value for the |SyncSwitch|.

Definition at line 21 of file sync_switch.cc.

21 : value_(value) {}
uint8_t value

Member Function Documentation

◆ Execute()

void fml::SyncSwitch::Execute ( const Handlers handlers) const

Diverge execution between true and false values of the SyncSwitch.

This can be called on any thread. Note that attempting to call |SetSwitch| inside of the handlers will result in a self deadlock.

Parameters
[in]handlersCalled for the correct value of the |SyncSwitch|.

Definition at line 23 of file sync_switch.cc.

References fml::SyncSwitch::Handlers::false_handler, and fml::SyncSwitch::Handlers::true_handler.

Referenced by TEST().

23  {
24  std::scoped_lock guard(mutex_);
25  if (value_) {
26  handlers.true_handler();
27  } else {
28  handlers.false_handler();
29  }
30 }

◆ SetSwitch()

void fml::SyncSwitch::SetSwitch ( bool  value)

Set the value of the SyncSwitch.

This can be called on any thread.

Parameters
[in]valueNew value for the |SyncSwitch|.

Definition at line 32 of file sync_switch.cc.

References value.

Referenced by TEST().

32  {
33  std::scoped_lock guard(mutex_);
34  value_ = value;
35 }
uint8_t value

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