@@ -394,11 +394,54 @@ VALUE rb_fiber_scheduler_io_close(VALUE scheduler, VALUE io);
394
394
*/
395
395
VALUE rb_fiber_scheduler_address_resolve (VALUE scheduler, VALUE hostname);
396
396
397
+ // The state of the blocking operation execution.
397
398
struct rb_fiber_scheduler_blocking_operation_state {
398
399
void *result;
399
400
int saved_errno;
400
401
};
401
402
403
+ // The opaque handle for the blocking operation.
404
+ typedef struct rb_fiber_scheduler_blocking_operation rb_fiber_scheduler_blocking_operation_t ;
405
+
406
+ /* *
407
+ * Extract the blocking operation handle from a BlockingOperationRuby object.
408
+ *
409
+ * This function safely extracts the opaque handle from a BlockingOperation VALUE
410
+ * while holding the GVL. The returned pointer can be passed to worker threads
411
+ * and used with rb_fiber_scheduler_blocking_operation_execute.
412
+ *
413
+ * @param[in] self The BlockingOperation VALUE to extract from
414
+ * @return The opaque struct pointer on success, NULL on error
415
+ * @note Experimental.
416
+ */
417
+ rb_fiber_scheduler_blocking_operation_t *rb_fiber_scheduler_blocking_operation_extract (VALUE self);
418
+
419
+ /* *
420
+ * Execute blocking operation from handle (GVL not required).
421
+ *
422
+ * This function executes a blocking operation using the opaque handle
423
+ * obtained from rb_fiber_scheduler_blocking_operation_extract.
424
+ * It can be called from native threads without holding the GVL.
425
+ *
426
+ * @param[in] blocking_operation The opaque handle.
427
+ * @return 0 on success, -1 on error.
428
+ * @note Experimental. Can be called from any thread without holding the GVL
429
+ */
430
+ int rb_fiber_scheduler_blocking_operation_execute (rb_fiber_scheduler_blocking_operation_t *blocking_operation);
431
+
432
+ /* *
433
+ * Cancel a blocking operation.
434
+ *
435
+ * This function cancels a blocking operation. If the operation is queued,
436
+ * it just marks it as cancelled. If it's executing, it marks it as cancelled
437
+ * and calls the unblock function to interrupt the operation.
438
+ *
439
+ * @param blocking_operation The opaque struct pointer
440
+ * @return 1 if unblock function was called, 0 if just marked cancelled, -1 on error
441
+ * @note Experimental.
442
+ */
443
+ int rb_fiber_scheduler_blocking_operation_cancel (rb_fiber_scheduler_blocking_operation_t *blocking_operation);
444
+
402
445
/* *
403
446
* Defer the execution of the passed function to the scheduler.
404
447
*
0 commit comments