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/receiver.h>
6 #include <lib/async/task.h>
7 #include <lib/async/time.h>
8 #include <lib/async/trap.h>
9 #include <lib/async/wait.h>
10 
async_now(async_dispatcher_t * dispatcher)11 zx_time_t async_now(async_dispatcher_t* dispatcher) {
12     return dispatcher->ops->v1.now(dispatcher);
13 }
14 
async_begin_wait(async_dispatcher_t * dispatcher,async_wait_t * wait)15 zx_status_t async_begin_wait(async_dispatcher_t* dispatcher, async_wait_t* wait) {
16     return dispatcher->ops->v1.begin_wait(dispatcher, wait);
17 }
18 
async_cancel_wait(async_dispatcher_t * dispatcher,async_wait_t * wait)19 zx_status_t async_cancel_wait(async_dispatcher_t* dispatcher, async_wait_t* wait) {
20     return dispatcher->ops->v1.cancel_wait(dispatcher, wait);
21 }
22 
async_post_task(async_dispatcher_t * dispatcher,async_task_t * task)23 zx_status_t async_post_task(async_dispatcher_t* dispatcher, async_task_t* task) {
24     return dispatcher->ops->v1.post_task(dispatcher, task);
25 }
26 
async_cancel_task(async_dispatcher_t * dispatcher,async_task_t * task)27 zx_status_t async_cancel_task(async_dispatcher_t* dispatcher, async_task_t* task) {
28     return dispatcher->ops->v1.cancel_task(dispatcher, task);
29 }
30 
async_queue_packet(async_dispatcher_t * dispatcher,async_receiver_t * receiver,const zx_packet_user_t * data)31 zx_status_t async_queue_packet(async_dispatcher_t* dispatcher, async_receiver_t* receiver,
32                                const zx_packet_user_t* data) {
33     return dispatcher->ops->v1.queue_packet(dispatcher, receiver, data);
34 }
35 
async_set_guest_bell_trap(async_dispatcher_t * dispatcher,async_guest_bell_trap_t * trap,zx_handle_t guest,zx_vaddr_t addr,size_t length)36 zx_status_t async_set_guest_bell_trap(async_dispatcher_t* dispatcher, async_guest_bell_trap_t* trap,
37                                       zx_handle_t guest, zx_vaddr_t addr, size_t length) {
38     return dispatcher->ops->v1.set_guest_bell_trap(dispatcher, trap, guest, addr, length);
39 }
40 
async_bind_exception_port(async_dispatcher_t * dispatcher,async_exception_t * exception)41 zx_status_t async_bind_exception_port(async_dispatcher_t* dispatcher,
42                                       async_exception_t* exception) {
43     if (dispatcher->ops->version < ASYNC_OPS_V2)
44         return ZX_ERR_NOT_SUPPORTED;
45     return dispatcher->ops->v2.bind_exception_port(dispatcher, exception);
46 }
47 
async_unbind_exception_port(async_dispatcher_t * dispatcher,async_exception_t * exception)48 zx_status_t async_unbind_exception_port(async_dispatcher_t* dispatcher,
49                                         async_exception_t* exception) {
50     if (dispatcher->ops->version < ASYNC_OPS_V2)
51         return ZX_ERR_NOT_SUPPORTED;
52     return dispatcher->ops->v2.unbind_exception_port(dispatcher, exception);
53 }
54 
async_resume_from_exception(async_dispatcher_t * dispatcher,async_exception_t * exception,zx_handle_t task,uint32_t options)55 zx_status_t async_resume_from_exception(async_dispatcher_t* dispatcher,
56                                         async_exception_t* exception,
57                                         zx_handle_t task,
58                                         uint32_t options) {
59     if (dispatcher->ops->version < ASYNC_OPS_V2)
60         return ZX_ERR_NOT_SUPPORTED;
61     return dispatcher->ops->v2.resume_from_exception(dispatcher, exception, task, options);
62 }
63