@@ -303,15 +303,15 @@ which would call back to `callback()` in Rust.
303
303
304
304
## Targetting callbacks to Rust objects
305
305
306
- The former example showed how a global function can be called from C-Code .
306
+ The former example showed how a global function can be called from C code .
307
307
However it is often desired that the callback is targetted to a special
308
308
Rust object. This could be the object that represents the wrapper for the
309
309
respective C object.
310
310
311
311
This can be achieved by passing an unsafe pointer to the object down to the
312
312
C library. The C library can then include the pointer to the Rust object in
313
- the notification. This will provide a unsafe possibility to access the
314
- referenced Rust object in callback .
313
+ the notification. This will allow the callback to unsafely access the
314
+ referenced Rust object.
315
315
316
316
Rust code:
317
317
~~~~ {.xfail-test}
@@ -364,25 +364,25 @@ void trigger_callback() {
364
364
365
365
## Asynchronous callbacks
366
366
367
- In the already given examples the callbacks are invoked as a direct reaction
367
+ In the previously given examples the callbacks are invoked as a direct reaction
368
368
to a function call to the external C library.
369
- The control over the current thread switched from Rust to C to Rust for the
369
+ The control over the current thread is switched from Rust to C to Rust for the
370
370
execution of the callback, but in the end the callback is executed on the
371
371
same thread (and Rust task) that lead called the function which triggered
372
372
the callback.
373
373
374
- Things get more complicated when the external library spawns it's own threads
374
+ Things get more complicated when the external library spawns its own threads
375
375
and invokes callbacks from there.
376
- In these cases access to Rust data structures inside he callbacks is
376
+ In these cases access to Rust data structures inside the callbacks is
377
377
especially unsafe and proper synchronization mechanisms must be used.
378
- Besides classical synchronization mechanisms like mutexes one possibility in
378
+ Besides classical synchronization mechanisms like mutexes, one possibility in
379
379
Rust is to use channels (in ` std::comm ` ) to forward data from the C thread
380
380
that invoked the callback into a Rust task.
381
381
382
382
If an asychronous callback targets a special object in the Rust address space
383
383
it is also absolutely necessary that no more callbacks are performed by the
384
- C library after the respective Rust object get's destroyed.
385
- This can be achieved by unregistering the callback it the object's
384
+ C library after the respective Rust object gets destroyed.
385
+ This can be achieved by unregistering the callback in the object's
386
386
destructor and designing the library in a way that guarantees that no
387
387
callback will be performed after unregistration.
388
388
0 commit comments