@@ -107,35 +107,34 @@ end
107
107
# argument of the @ccall. Currently we pass a pointer to a Base.Event that must be notified to
108
108
# wakeup the appropriate task.
109
109
Base. @ccallable function notify_result (event_ptr:: Ptr{Nothing} ):: Cint
110
- event = unsafe_pointer_to_objref (event_ptr)
110
+ event = unsafe_pointer_to_objref (event_ptr):: Base.Event
111
111
notify (event)
112
112
return 0
113
113
end
114
114
115
115
# A dict of all tasks that are waiting some result from Rust
116
116
# and should thus not be garbage collected.
117
117
# This copies the behavior of Base.preserve_handle.
118
- const tasks_in_flight = IdDict ()
118
+ const tasks_in_flight = IdDict {Task, Int64} ()
119
119
const preserve_task_lock = Threads. SpinLock ()
120
120
function preserve_task (x:: Task )
121
- lock ( preserve_task_lock)
122
- v = get (tasks_in_flight, x, 0 ):: Int
123
- tasks_in_flight[x] = v + 1
124
- unlock (preserve_task_lock)
121
+ @ lock preserve_task_lock begin
122
+ v = get (tasks_in_flight, x, 0 ):: Int
123
+ tasks_in_flight[x] = v + 1
124
+ end
125
125
nothing
126
126
end
127
127
function unpreserve_task (x:: Task )
128
- lock ( preserve_task_lock)
129
- v = get (tasks_in_flight, x, 0 ):: Int
130
- if v == 0
131
- unlock (preserve_task_lock )
132
- error ( " unbalanced call to unpreserve_task for $( typeof (x)) " )
133
- elseif v == 1
134
- pop! (tasks_in_flight, x)
135
- else
136
- tasks_in_flight[x] = v - 1
128
+ @ lock preserve_task_lock begin
129
+ v = get (tasks_in_flight, x, 0 ):: Int
130
+ if v == 0
131
+ error ( " unbalanced call to unpreserve_task for $( typeof (x)) " )
132
+ elseif v == 1
133
+ pop! (tasks_in_flight, x)
134
+ else
135
+ tasks_in_flight[x] = v - 1
136
+ end
137
137
end
138
- unlock (preserve_task_lock)
139
138
nothing
140
139
end
141
140
@@ -197,7 +196,7 @@ function throw_on_error(response, operation, exception)
197
196
return :( $ (esc (:($ response. result == 1 ))) ? throw ($ exception ($ response_error_to_string ($ (esc (response)), $ operation))) : $ (nothing ) )
198
197
end
199
198
200
- function ensure_wait (event)
199
+ function ensure_wait (event:: Base.Event )
201
200
for i in 1 : 20
202
201
try
203
202
return wait (event)
@@ -210,7 +209,7 @@ function ensure_wait(event)
210
209
exit (1 )
211
210
end
212
211
213
- function wait_or_cancel (event, response)
212
+ function wait_or_cancel (event:: Base.Event , response)
214
213
try
215
214
return wait (event)
216
215
catch e
0 commit comments