1 // Copyright 2018 The Fuchsia 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 // Can't compile this for Zircon userspace yet since libstdc++ isn't available.
6 #ifndef FIT_NO_STD_FOR_ZIRCON_USERSPACE
7 
8 #include <lib/fit/sequencer.h>
9 
10 namespace fit {
11 
sequencer()12 sequencer::sequencer() {
13     // Capture a new consumer and intentionally abandon its associated
14     // completer so that a promise chained onto the consumer using
15     // |promise_or()| will become immediately runnable.
16     fit::bridge<> bridge;
17     prior_ = std::move(bridge.consumer);
18 }
19 
20 sequencer::~sequencer() = default;
21 
swap_prior(fit::consumer<> new_prior)22 fit::consumer<> sequencer::swap_prior(fit::consumer<> new_prior) {
23     std::lock_guard<std::mutex> lock(mutex_);
24     fit::consumer<> old_prior = std::move(prior_);
25     prior_ = std::move(new_prior);
26     return old_prior;
27 }
28 
29 } // namespace fit
30 
31 #endif // FIT_NO_STD_FOR_ZIRCON_USERSPACE
32