Flutter Engine
sync_switch.cc
Go to the documentation of this file.
1 // Copyright 2013 The Flutter Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file.
4 
5 #include "flutter/fml/synchronization/sync_switch.h"
6 
7 namespace fml {
8 
10  const std::function<void()>& handler) {
11  true_handler = std::move(handler);
12  return *this;
13 }
14 
16  const std::function<void()>& handler) {
17  false_handler = std::move(handler);
18  return *this;
19 }
20 
22 
23 SyncSwitch::SyncSwitch(bool value) : value_(value) {}
24 
26  std::scoped_lock guard(mutex_);
27  if (value_) {
28  handlers.true_handler();
29  } else {
30  handlers.false_handler();
31  }
32 }
33 
35  std::scoped_lock guard(mutex_);
36  value_ = value;
37 }
38 
39 } // namespace fml
SyncSwitch()
Create a |SyncSwitch| with the false value.
Definition: sync_switch.cc:21
Handlers & SetIfTrue(const std::function< void()> &handler)
Sets the handler that will be executed if the |SyncSwitch| is true.
Definition: sync_switch.cc:9
void SetSwitch(bool value)
Definition: sync_switch.cc:34
std::function< void()> false_handler
Definition: sync_switch.h:32
Dart_NativeFunction function
Definition: fuchsia.cc:51
std::function< void()> true_handler
Definition: sync_switch.h:31
Definition: ascii_trie.cc:9
uint8_t value
Handlers & SetIfFalse(const std::function< void()> &handler)
Sets the handler that will be executed if the |SyncSwitch| is false.
Definition: sync_switch.cc:15
void Execute(const Handlers &handlers)
Definition: sync_switch.cc:25
Represents the 2 code paths available when calling |SyncSwitch::Execute|.
Definition: sync_switch.h:24