|
19 | 19 |
|
20 | 20 | (memory 1) |
21 | 21 | (global $blocked (mut i32) (i32.const 1)) |
22 | | - (global $counter (mut i32) (i32.const 2)) |
| 22 | + (global $counter (mut i32) (i32.const 3)) |
23 | 23 |
|
24 | 24 | ;; 'blocking-call' cooperatively "spin-waits" until $blocked is 0. |
25 | 25 | (func $blocking-call (export "blocking-call") (result i32) |
|
135 | 135 | ;; (on $AsyncInner.blocking-call). because 'sync-func1/2' are in different instances, |
136 | 136 | ;; both calls will reach the STARTED state. |
137 | 137 | (local.set $ret (call $sync-func1 (i32.const 8))) |
138 | | - (if (i32.ne (i32.const 0x21 (; STARTED=1 | (subtask=2 << 4) ;)) (local.get $ret)) |
139 | | - (then unreachable)) |
140 | | - (call $waitable.join (i32.const 2) (global.get $ws)) |
141 | | - (local.set $ret (call $sync-func2 (i32.const 12))) |
142 | 138 | (if (i32.ne (i32.const 0x31 (; STARTED=1 | (subtask=3 << 4) ;)) (local.get $ret)) |
143 | 139 | (then unreachable)) |
144 | 140 | (call $waitable.join (i32.const 3) (global.get $ws)) |
| 141 | + (local.set $ret (call $sync-func2 (i32.const 12))) |
| 142 | + (if (i32.ne (i32.const 0x41 (; STARTED=1 | (subtask=4 << 4) ;)) (local.get $ret)) |
| 143 | + (then unreachable)) |
| 144 | + (call $waitable.join (i32.const 4) (global.get $ws)) |
145 | 145 |
|
146 | 146 | ;; now start another pair of 'sync-func1/2' calls, both of which should see auto |
147 | 147 | ;; backpressure and get stuck in the STARTING state. |
148 | 148 | (local.set $ret (call $sync-func1 (i32.const 16))) |
149 | | - (if (i32.ne (i32.const 0x40 (; STARTING=0 | (subtask=4 << 4) ;)) (local.get $ret)) |
150 | | - (then unreachable)) |
151 | | - (call $waitable.join (i32.const 4) (global.get $ws)) |
152 | | - (local.set $ret (call $sync-func2 (i32.const 20))) |
153 | 149 | (if (i32.ne (i32.const 0x50 (; STARTING=0 | (subtask=5 << 4) ;)) (local.get $ret)) |
154 | 150 | (then unreachable)) |
155 | 151 | (call $waitable.join (i32.const 5) (global.get $ws)) |
| 152 | + (local.set $ret (call $sync-func2 (i32.const 20))) |
| 153 | + (if (i32.ne (i32.const 0x60 (; STARTING=0 | (subtask=6 << 4) ;)) (local.get $ret)) |
| 154 | + (then unreachable)) |
| 155 | + (call $waitable.join (i32.const 6) (global.get $ws)) |
156 | 156 |
|
157 | 157 | ;; this POLL should return that nothing is ready |
158 | 158 | (i32.or (i32.const 3 (; POLL ;)) (i32.shl (global.get $ws) (i32.const 4))) |
|
175 | 175 | (then unreachable)) |
176 | 176 |
|
177 | 177 | ;; if we receive a SUBTASK STARTED event, it should only be for the 3rd or |
178 | | - ;; 4th subtask (at indices 4/5, resp), so keep waiting for completion |
| 178 | + ;; 4th subtask (at indices 5/6, resp), so keep waiting for completion |
179 | 179 | (if (i32.eq (local.get $payload) (i32.const 1 (; STARTED ;))) (then |
180 | 180 | (if (i32.and |
181 | | - (i32.ne (local.get $index) (i32.const 4)) |
182 | | - (i32.ne (local.get $index) (i32.const 5))) |
| 181 | + (i32.ne (local.get $index) (i32.const 5)) |
| 182 | + (i32.ne (local.get $index) (i32.const 6))) |
183 | 183 | (then unreachable)) |
184 | 184 | (return (i32.or (i32.const 2 (; WAIT ;)) (i32.shl (global.get $ws) (i32.const 4)))) |
185 | 185 | )) |
186 | 186 |
|
187 | 187 | ;; when we receive a SUBTASK RETURNED event, check the return value is equal to the |
188 | | - ;; subtask index (which we've ensured by having $AsyncInner.$counter start at 2, the |
189 | | - ;; first subtask index. The address of the return buffer is the index*4. |
| 188 | + ;; subtask index (which we've ensured by having $AsyncInner.$counter start at 3, the |
| 189 | + ;; first subtask index. The address of the return buffer is the index-1*4. |
190 | 190 | (if (i32.ne (local.get $payload) (i32.const 2 (; RETURNED ;))) |
191 | 191 | (then unreachable)) |
192 | | - (if (i32.ne (local.get $index) (i32.load (i32.mul (local.get $index) (i32.const 4)))) |
| 192 | + (if (i32.ne (local.get $index) (i32.load (i32.mul (i32.sub (local.get $index) (i32.const 1)) (i32.const 4)))) |
193 | 193 | (then unreachable)) |
194 | 194 |
|
195 | 195 | ;; decrement $remain and exit if 0 |
|
0 commit comments