#include <sync_switch.h>
Classes | |
| struct | Handlers |
| Represents the 2 code paths available when calling |SyncSwitchExecute|. More... | |
| class | Observer |
| Observes changes to the SyncSwitch. More... | |
Public Member Functions | |
| SyncSwitch (bool value=false) | |
| void | Execute (const Handlers &handlers) const |
| void | SetSwitch (bool value) |
| void | AddObserver (Observer *observer) const |
| Threadsafe. | |
| void | RemoveObserver (Observer *observer) const |
| Threadsafe. | |
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 22 of file sync_switch.h.
|
explicit |
Create a |SyncSwitch| with the specified value.
| [in] | value | Default value for the |SyncSwitch|. |
Definition at line 24 of file sync_switch.cc.
References value.
| void fml::SyncSwitch::AddObserver | ( | Observer * | observer | ) | const |
Threadsafe.
Definition at line 45 of file sync_switch.cc.
| 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.
| [in] | handlers | Called for the correct value of the |SyncSwitch|. |
Definition at line 26 of file sync_switch.cc.
References fml::SyncSwitch::Handlers::false_handler, and fml::SyncSwitch::Handlers::true_handler.
| void fml::SyncSwitch::RemoveObserver | ( | Observer * | observer | ) | const |
Threadsafe.
Definition at line 53 of file sync_switch.cc.
| void fml::SyncSwitch::SetSwitch | ( | bool | value | ) |
Set the value of the SyncSwitch.
This can be called on any thread.
| [in] | value | New value for the |SyncSwitch|. |
Definition at line 35 of file sync_switch.cc.
References value.