diff --git a/ffi/ffi_context.nim b/ffi/ffi_context.nim index 41bd904..d11e295 100644 --- a/ffi/ffi_context.nim +++ b/ffi/ffi_context.nim @@ -518,11 +518,11 @@ proc stopAndJoinThreads*[T](ctx: ptr FFIContext[T]): Result[void, string] = proc requestRecycle*[T]( ctx: ptr FFIContext[T], callback: FFICallBack, userData: pointer ): Result[void, string] = - ## Asks the FFI thread to recycle the context and fire `callback` with the - ## outcome (RET_OK drained, RET_ERR stuck). NON-BLOCKING. + ## Starts ctx recycle process without stopping its worker, so the next + ## createFFIContext reuses the same threads and fds. ## - ## Order matters: set the callback before flipping to RecyclePending (the flip is - ## the trigger), under `lock` to serialise the gate with sendRequestToFFIThread. + ## During recycling, the FFI thread drains the handlers, frees the lib and releases + ## the context, then fires `callback` (RET_OK drained, RET_ERR stuck). ctx.recycleCallback = callback ctx.recycleUserData = userData diff --git a/ffi/ffi_context_pool.nim b/ffi/ffi_context_pool.nim index acfb72c..112f75d 100644 --- a/ffi/ffi_context_pool.nim +++ b/ffi/ffi_context_pool.nim @@ -45,13 +45,6 @@ proc createFFIContext*[T]( proc releaseFFIContext*[T]( ctx: ptr FFIContext[T], callback: FFICallBack, userData: pointer ): Result[void, string] = - ## Parks a context for reuse without stopping its worker, so the next - ## createFFIContext reuses the same threads and fds. Steady-state cleanup path - ## for the generated destructor; destroyFFIContext is for failure/non-pool use. - ## - ## NON-BLOCKING: the FFI thread drains the handlers, frees the lib and releases - ## the context, then fires `callback` (RET_OK drained, RET_ERR stuck). The context - ## returns to the pool from that thread, so a reused context never carries a straggler. return ctx.requestRecycle(callback, userData) proc destroyFFIContext*[T](