Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
43 changes: 43 additions & 0 deletions include/ruby/fiber/scheduler.h
Original file line number Diff line number Diff line change
Expand Up @@ -394,11 +394,54 @@ VALUE rb_fiber_scheduler_io_close(VALUE scheduler, VALUE io);
*/
VALUE rb_fiber_scheduler_address_resolve(VALUE scheduler, VALUE hostname);

// The state of the blocking operation execution.
struct rb_fiber_scheduler_blocking_operation_state {
void *result;
int saved_errno;
};

// The opaque handle for the blocking operation.
typedef struct rb_fiber_scheduler_blocking_operation rb_fiber_scheduler_blocking_operation_t;

/**
* Extract the blocking operation handle from a BlockingOperationRuby object.
*
* This function safely extracts the opaque handle from a BlockingOperation VALUE
* while holding the GVL. The returned pointer can be passed to worker threads
* and used with rb_fiber_scheduler_blocking_operation_execute.
*
* @param[in] self The BlockingOperation VALUE to extract from
* @return The opaque struct pointer on success, NULL on error
* @note Experimental.
*/
rb_fiber_scheduler_blocking_operation_t *rb_fiber_scheduler_blocking_operation_extract(VALUE self);

/**
* Execute blocking operation from handle (GVL not required).
*
* This function executes a blocking operation using the opaque handle
* obtained from rb_fiber_scheduler_blocking_operation_extract.
* It can be called from native threads without holding the GVL.
*
* @param[in] blocking_operation The opaque handle.
* @return 0 on success, -1 on error.
* @note Experimental. Can be called from any thread without holding the GVL
*/
int rb_fiber_scheduler_blocking_operation_execute(rb_fiber_scheduler_blocking_operation_t *blocking_operation);

/**
* Cancel a blocking operation.
*
* This function cancels a blocking operation. If the operation is queued,
* it just marks it as cancelled. If it's executing, it marks it as cancelled
* and calls the unblock function to interrupt the operation.
*
* @param blocking_operation The opaque struct pointer
* @return 1 if unblock function was called, 0 if just marked cancelled, -1 on error
* @note Experimental.
*/
int rb_fiber_scheduler_blocking_operation_cancel(rb_fiber_scheduler_blocking_operation_t *blocking_operation);

/**
* Defer the execution of the passed function to the scheduler.
*
Expand Down
2 changes: 1 addition & 1 deletion inits.c
Original file line number Diff line number Diff line change
Expand Up @@ -63,9 +63,9 @@ rb_call_inits(void)
CALL(ISeq);
CALL(Thread);
CALL(signal);
CALL(Cont);
CALL(Fiber_Scheduler);
CALL(process);
CALL(Cont);
CALL(Rational);
CALL(Complex);
CALL(MemoryView);
Expand Down
2 changes: 1 addition & 1 deletion internal/io.h
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ struct rb_io_blocking_operation {
// The linked list data structure.
struct ccan_list_node list;

// The execution context of the blocking operation:
// The execution context of the blocking operation.
struct rb_execution_context_struct *ec;
};

Expand Down
Loading
Loading