mruby/c VM Source Code master (2026/08/06)
Loading...
Searching...
No Matches
c_task_queue.c File Reference

Task::Queue for mruby/c. More...

#include "mrubyc.h"
#include "_autogen_class_task_queue.h"
Include dependency graph for c_task_queue.c:

Go to the source code of this file.

Functions

static int queue_wake_one_waiter (void *q)
static int queue_wake_all_waiters (void *q)
static int queue_is_closed (mrbc_value *queue)
void mrbc_init_task_queue (void)
mrbc_task_queue_push_result mrbc_task_queue_push (mrbc_value *queue, mrbc_value *value)

Variables

static mrbc_value wait_retry_
static mrbc_value wait_timeout_
static struct RClasstask_error_class_
static mrbc_sym sym_items_
static mrbc_sym sym_closed_

Detailed Description

Task::Queue for mruby/c.

Copyright (C) 2026-      HASUMI Hitoshi

This file is distributed under BSD 3-Clause License.

Definition in file c_task_queue.c.

Function Documentation

◆ mrbc_init_task_queue()

void mrbc_init_task_queue ( void )

initialize

Definition at line 398 of file c_task_queue.c.

Here is the call graph for this function:
Here is the caller graph for this function:

◆ mrbc_task_queue_push()

mrbc_task_queue_push_result mrbc_task_queue_push ( mrbc_value * queue,
mrbc_value * value )

Push a value into a Task::Queue from C and wake one waiting task.

Ownership of value stays with the caller; the queue takes its own reference. An invalid receiver and a closed queue are reported as a result code rather than an exception, so this is usable where no VM context is at hand.

(NOTE) This grows the item array through the mruby/c allocator and edits the task queues, so it must NOT be called from an interrupt handler, nor from any context that could re-enter the VM. There is no portable way to detect that at run time, so the caller is responsible for honouring it. To feed a queue from an interrupt, buffer the data in an ISR-safe ring buffer and push it from a task.

A caller running inside the VM must set flag_preemption when MRBC_TASK_QUEUE_PUSH_OK_WOKE is returned, otherwise the woken task waits for the current time slice to expire. See c_task_queue_push().

Parameters
queueTask::Queue instance (or an instance of its subclass).
valuevalue to push.
Returns
result code. see mrbc_task_queue_push_result.

Definition at line 441 of file c_task_queue.c.

Here is the call graph for this function:

◆ queue_is_closed()

int queue_is_closed ( mrbc_value * queue)
static

Check whether the queue has been closed.

(NOTE) @closed only ever holds true or false, so the decref is a no-op in practice. It is kept to stay paired with the incref done by mrbc_instance_getiv().

Parameters
queueTask::Queue instance.
Returns
Non-zero if the queue is closed.

Definition at line 123 of file c_task_queue.c.

Here is the call graph for this function:
Here is the caller graph for this function:

◆ queue_wake_all_waiters()

int queue_wake_all_waiters ( void * q)
static

Wake all tasks waiting on this queue (used by close).

Parameters
qQueue instance the tasks are waiting on.
Returns
Non-zero if any task was woken.

Definition at line 88 of file c_task_queue.c.

Here is the call graph for this function:

◆ queue_wake_one_waiter()

int queue_wake_one_waiter ( void * q)
static

Wake the highest-priority task waiting on this queue.

Parameters
qQueue instance the tasks are waiting on.
Returns
Non-zero if a task was woken.

Definition at line 59 of file c_task_queue.c.

Here is the call graph for this function:
Here is the caller graph for this function:

Variable Documentation

◆ sym_closed_

mrbc_sym sym_closed_
static

Definition at line 47 of file c_task_queue.c.

◆ sym_items_

mrbc_sym sym_items_
static

Definition at line 46 of file c_task_queue.c.

◆ task_error_class_

struct RClass* task_error_class_
static

Definition at line 43 of file c_task_queue.c.

◆ wait_retry_

mrbc_value wait_retry_
static

Definition at line 34 of file c_task_queue.c.

◆ wait_timeout_

mrbc_value wait_timeout_
static

Definition at line 40 of file c_task_queue.c.