Book a Demo!
CoCalc Logo Icon
StoreFeaturesDocsShareSupportNewsAboutPoliciesSign UpSign In
bytecodealliance
GitHub Repository: bytecodealliance/wasmtime
Path: blob/main/crates/test-programs/src/async_.rs
1693 views
1
#[cfg(target_arch = "wasm32")]
2
#[link(wasm_import_module = "$root")]
3
unsafe extern "C" {
4
#[link_name = "[waitable-set-new]"]
5
pub fn waitable_set_new() -> u32;
6
}
7
#[cfg(not(target_arch = "wasm32"))]
8
pub unsafe fn waitable_set_new() -> u32 {
9
unreachable!()
10
}
11
12
#[cfg(target_arch = "wasm32")]
13
#[link(wasm_import_module = "$root")]
14
unsafe extern "C" {
15
#[link_name = "[waitable-join]"]
16
pub fn waitable_join(waitable: u32, set: u32);
17
}
18
#[cfg(not(target_arch = "wasm32"))]
19
pub unsafe fn waitable_join(_: u32, _: u32) {
20
unreachable!()
21
}
22
23
#[cfg(target_arch = "wasm32")]
24
#[link(wasm_import_module = "$root")]
25
unsafe extern "C" {
26
#[link_name = "[waitable-set-drop]"]
27
pub fn waitable_set_drop(set: u32);
28
}
29
#[cfg(not(target_arch = "wasm32"))]
30
pub unsafe fn waitable_set_drop(_: u32) {
31
unreachable!()
32
}
33
34
#[cfg(not(target_arch = "wasm32"))]
35
pub unsafe fn waitable_set_poll_raw(_: u32, _: *mut u32) -> u32 {
36
unreachable!()
37
}
38
#[cfg(target_arch = "wasm32")]
39
#[link(wasm_import_module = "$root")]
40
unsafe extern "C" {
41
#[link_name = "[waitable-set-poll]"]
42
pub fn waitable_set_poll_raw(_: u32, _: *mut u32) -> u32;
43
}
44
45
pub fn waitable_set_poll(set: u32) -> (u32, u32, u32) {
46
let mut payload = [0u32; 2];
47
let ret0 = unsafe { waitable_set_poll_raw(set, payload.as_mut_ptr()) };
48
(ret0, payload[0], payload[1])
49
}
50
51
#[cfg(target_arch = "wasm32")]
52
#[link(wasm_import_module = "$root")]
53
unsafe extern "C" {
54
#[link_name = "[waitable-set-wait]"]
55
pub fn waitable_set_wait(set: u32, results: *mut u32) -> u32;
56
}
57
#[cfg(not(target_arch = "wasm32"))]
58
pub unsafe extern "C" fn waitable_set_wait(_set: u32, _results: *mut u32) -> u32 {
59
unreachable!()
60
}
61
62
#[cfg(target_arch = "wasm32")]
63
#[link(wasm_import_module = "$root")]
64
unsafe extern "C" {
65
#[link_name = "[subtask-drop]"]
66
pub fn subtask_drop(task: u32);
67
}
68
#[cfg(not(target_arch = "wasm32"))]
69
pub unsafe fn subtask_drop(_: u32) {
70
unreachable!()
71
}
72
73
#[cfg(target_arch = "wasm32")]
74
#[link(wasm_import_module = "$root")]
75
unsafe extern "C" {
76
#[link_name = "[subtask-cancel]"]
77
pub fn subtask_cancel(task: u32) -> u32;
78
}
79
#[cfg(not(target_arch = "wasm32"))]
80
pub unsafe fn subtask_cancel(_: u32) -> u32 {
81
unreachable!()
82
}
83
84
#[cfg(target_arch = "wasm32")]
85
#[link(wasm_import_module = "$root")]
86
unsafe extern "C" {
87
#[link_name = "[async-lower][subtask-cancel]"]
88
pub fn subtask_cancel_async(task: u32) -> u32;
89
}
90
#[cfg(not(target_arch = "wasm32"))]
91
pub unsafe fn subtask_cancel_async(_: u32) -> u32 {
92
unreachable!()
93
}
94
95
#[cfg(target_arch = "wasm32")]
96
#[link(wasm_import_module = "$root")]
97
unsafe extern "C" {
98
#[link_name = "[context-get-0]"]
99
pub fn context_get() -> u32;
100
}
101
#[cfg(not(target_arch = "wasm32"))]
102
pub unsafe fn context_get() -> u32 {
103
unreachable!()
104
}
105
106
#[cfg(target_arch = "wasm32")]
107
#[link(wasm_import_module = "$root")]
108
unsafe extern "C" {
109
#[link_name = "[context-set-0]"]
110
pub fn context_set(value: u32);
111
}
112
#[cfg(not(target_arch = "wasm32"))]
113
pub unsafe fn context_set(_: u32) {
114
unreachable!()
115
}
116
117
#[cfg(target_arch = "wasm32")]
118
#[link(wasm_import_module = "[export]$root")]
119
unsafe extern "C" {
120
#[link_name = "[task-cancel]"]
121
pub fn task_cancel();
122
}
123
#[cfg(not(target_arch = "wasm32"))]
124
pub unsafe extern "C" fn task_cancel() {
125
unreachable!()
126
}
127
128
pub const STATUS_STARTING: u32 = 0;
129
pub const STATUS_STARTED: u32 = 1;
130
pub const STATUS_RETURNED: u32 = 2;
131
pub const STATUS_START_CANCELLED: u32 = 3;
132
pub const STATUS_RETURN_CANCELLED: u32 = 4;
133
134
pub const EVENT_NONE: u32 = 0;
135
pub const EVENT_SUBTASK: u32 = 1;
136
pub const EVENT_STREAM_READ: u32 = 2;
137
pub const EVENT_STREAM_WRITE: u32 = 3;
138
pub const EVENT_FUTURE_READ: u32 = 4;
139
pub const EVENT_FUTURE_WRITE: u32 = 5;
140
pub const EVENT_CANCELLED: u32 = 6;
141
142
pub const CALLBACK_CODE_EXIT: u32 = 0;
143
pub const CALLBACK_CODE_YIELD: u32 = 1;
144
pub const CALLBACK_CODE_WAIT: u32 = 2;
145
pub const CALLBACK_CODE_POLL: u32 = 3;
146
147
pub const BLOCKED: u32 = 0xffff_ffff;
148
pub const DROPPED: u32 = 1;
149
pub const COMPLETED: u32 = 0;
150
151