1 // Copyright 2017 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 #include <lib/async-loop/cpp/loop.h>
6 
7 #include <zircon/assert.h>
8 
9 namespace async {
10 
Loop(const async_loop_config_t * config)11 Loop::Loop(const async_loop_config_t* config) {
12     zx_status_t status = async_loop_create(config, &loop_);
13     ZX_ASSERT_MSG(status == ZX_OK, "status=%d", status);
14 }
15 
~Loop()16 Loop::~Loop() {
17     async_loop_destroy(loop_);
18 }
19 
Shutdown()20 void Loop::Shutdown() {
21     async_loop_shutdown(loop_);
22 }
23 
Run(zx::time deadline,bool once)24 zx_status_t Loop::Run(zx::time deadline, bool once) {
25     return async_loop_run(loop_, deadline.get(), once);
26 }
27 
RunUntilIdle()28 zx_status_t Loop::RunUntilIdle() {
29     return async_loop_run_until_idle(loop_);
30 }
31 
Quit()32 void Loop::Quit() {
33     async_loop_quit(loop_);
34 }
35 
ResetQuit()36 zx_status_t Loop::ResetQuit() {
37     return async_loop_reset_quit(loop_);
38 }
39 
GetState() const40 async_loop_state_t Loop::GetState() const {
41     return async_loop_get_state(loop_);
42 }
43 
StartThread(const char * name,thrd_t * out_thread)44 zx_status_t Loop::StartThread(const char* name, thrd_t* out_thread) {
45     return async_loop_start_thread(loop_, name, out_thread);
46 }
47 
JoinThreads()48 void Loop::JoinThreads() {
49     async_loop_join_threads(loop_);
50 }
51 
52 } // namespace async
53