NAME ^

src/events.c - Event handling stuff

DESCRIPTION ^

An event_thread handles async events for all interpreters. When events are due, they are placed in per interpreter task_queues, where they are handled then by the check_event* opcodes.

IO events and signals are caught in the io_thread, which again dispatches these to one or all interpreters.

Signal Handling ^

sig_handler

Handle signal signum.

TODO - Only SIGHUP is handled at the moment for testing

Parrot_sigaction

Signal handlers are common to all threads, signal block masks are specific, so we install one handler then block that signal and unblock it in the thread, that will receive that signal.

Initialization ^

init_events_first

Init event system for first interpreter.

init_events_all

Init events for all interpreters.

Parrot_init_events

Initialize the event system.

Event Handler Functions ^

Parrot_schedule_event

Create queue entry and insert event into task queue.

Parrot_new_timer_event

Create a new timer event due at diff from now, repeated at interval and running the passed sub.

Parrot_new_cb_event

Prepare and schedule a callback event.

Parrot_del_timer_event

Deactivate the timer identified by timer.

Parrot_new_terminate_event

Create a terminate event, interpreter will leave the run-loop when this event arrives.

Parrot_new_suspend_for_gc_event

Create a suspend-for-GC event, interpreter will wait on a condition variable for GC to finish when the event arrives.

Parrot_kill_event_loop

Schedule event-loop terminate event. This shuts down the event thread.

Parrot_schedule_interp_qentry

Put a queue entry into the interpreters task queue and enable event checking for the interpreter.

Parrot_schedule_broadcast_qentry

Broadcast an event.

IO Thread Handling ^

io_thread

The IO thread uses select/poll to handle IO events and signals.

It waits on input from the message pipe to insert file descriptors in the wait sets.

stop_io_thread

Tell the IO thread to stop.

Event Handler Thread Functions ^

dup_entry

Duplicate queue entry.

dup_entry_interval

Duplicate timed entry and add interval to abs_time.

process_events

Do something, when an event arrived caller has locked the mutex returns 0 if event thread terminates.

event_thread

The event thread is started by the first interpreter. It handles all events for all interpreters.

Sleep Handling ^

wait_for_wakeup

Sleep on the event queue condition. If an event arrives, the event is processed. Terminate the loop if sleeping is finished.

Parrot_sleep_on_event

Go to sleep. This is called from the sleep opcode.

Event Handling for Run-Loops ^

Parrot_do_check_events

Explicitly sync called by the check_event opcode from run loops.

event_to_exception

Convert event to exception and throw it.

do_event

Run user code or such.

Parrot_do_handle_events

Called by the check_event__ opcode from run loops or from above. When called from the check_events__ opcode, we have to restore the op_func_table.

SEE ALSO ^

include/parrot/events.h and docs/dev/events.pod.


parrot