scoop:scoop.core:0.1.0
src/foreign_callback.scoop
Selected production source · src/foreign_callback.scoop
1
// GC-aware managed callback registration (spec 14.3, M13).3
/**4
* Controls whether a managed callback registration accepts repeated native invocation.5
*/6
public enum ForeignCallbackMode {7
/**8
* Allows repeated invocations until the registration is released or fails.9
*/10
Reusable,11
/**12
* Allows one terminal invocation of the managed callback.13
*/14
OneShot15
}17
/**18
* The observable lifecycle of a registered managed callback.19
*/20
public enum ForeignCallbackState {21
/**22
* The registration exists and has not begun invocation.23
*/24
Registered,25
/**26
* A native invocation is executing the managed callback.27
*/28
Active,29
/**30
* The one-shot callback completed successfully.31
*/32
Completed,33
/**34
* A callback invocation failed; its exception can be queried.35
*/36
Failed37
}39
/**40
* Pairs a callable native entry with the context pointer that must be passed at its declared41
* context argument position.42
*/43
public struct ForeignCallback<F>(44
val function: FunPtr<F>,45
val context: Ptr<Unit>46
)48
/**49
* Registers a managed non-suspending function behind a native trampoline. F must be an explicit50
* concrete C-safe signature; contextIndex and mode are compile-time constants, and the context51
* parameter is Ptr<Unit>. Reusable owners release after native unregister. A successful one-shot52
* launch transfers its worker ownership to the callback; retain a separate observer before that53
* transfer when needed.54
*/55
@Unsafe56
@Intrinsic("foreign_callback_register")57
public fun <F> foreignCallback(58
callback: Any,59
contextIndex: Long,60
mode: ForeignCallbackMode61
): ForeignCallback<F>63
/**64
* Acquires another reference to the callback registration for independent native ownership.65
*/66
@Unsafe67
@Intrinsic("foreign_callback_retain")68
public fun <F> retainForeignCallback(69
callback: ForeignCallback<F>70
): ForeignCallback<F>72
/**73
* Releases one acquired registration reference. Coordinate with native owners so no invocation can74
* use a freed registration.75
*/76
@Unsafe77
@Intrinsic("foreign_callback_release")78
public fun <F> releaseForeignCallback(callback: ForeignCallback<F>)80
/**81
* Reads the lifecycle state of a live callback registration.82
*/83
@Unsafe84
@Intrinsic("foreign_callback_state")85
public fun <F> foreignCallbackState(86
callback: ForeignCallback<F>87
): ForeignCallbackState89
/**90
* Returns the captured callback exception when invocation failed, or None when no failure is91
* recorded.92
*/93
@Unsafe94
@Intrinsic("foreign_callback_failure")95
public fun <F> foreignCallbackFailure(callback: ForeignCallback<F>): Throwable?