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
- static void sig_handlerHandle signal
- static void Parrot_sigactionSignal 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.
- static void Parrot_unblock_signalunblock a signal
- void Parrot_init_signalsSet up actions to handle signals.
Only SIGHUP handled at the moment.
signum.TODO - Only SIGHUP is handled at the moment for testing
Initialization
- static void init_events_firstInit event system for first interpreter.
- static void init_events_allInit events for all interpreters.
- void Parrot_init_eventsInitialize the event system.
Event Handler Functions
- void Parrot_schedule_eventCreate queue entry and insert event into task queue.
- static void schedule_signal_eventcreate and schedule a signal event
- void Parrot_new_timer_eventCreate a new timer event due at
- void Parrot_new_cb_eventPrepare and schedule a callback event.
- void Parrot_del_timer_eventDeactivate the timer identified by
- void Parrot_new_terminate_eventCreate a terminate event,
interpreter will leave the run-loop when this event arrives.
- void Parrot_new_suspend_for_gc_eventCreate a suspend-for-GC event,
interpreter will wait on a condition variable for GC to finish when the event arrives.
- void Parrot_kill_event_loopSchedule event-loop terminate event.
This shuts down the event thread.
- void Parrot_schedule_interp_qentryPut a queue entry into the interpreters task queue and enable event checking for the interpreter.
- void Parrot_schedule_broadcast_qentryBroadcast an event.
diff from now,
repeated at interval and running the passed sub.
timer.
IO Thread Handling
- static void store_io_eventStores an event in the event stack.
Allocates memory if necessary.
- static void io_thread_ready_rdTakes a list of pending i/o events and a file descriptor.
If the fd is ready to read,
the event is removed from the "pending" list and moved to the "scheduled" task queue.
- static void *io_threadThe 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.
- static void stop_io_threadTell the IO thread to stop.
- void Parrot_event_add_io_eventCreate new i/o event.
Event Handler Thread Functions
- static QUEUE_ENTRY *dup_entryDuplicate queue entry.
- static QUEUE_ENTRY *dup_entry_intervalDuplicate timed entry and add interval to
- static int process_eventsDo something,
when an event arrived caller has locked the mutex returns 0 if event thread terminates.
- static void *event_threadThe event thread is started by the first interpreter.
It handles all events for all interpreters.
abs_time.
Sleep Handling
- static opcode_t *wait_for_wakeupSleep on the event queue condition.
If an event arrives,
the event is processed.
Terminate the loop if sleeping is finished.
- opcode_t *Parrot_sleep_on_eventGo to sleep.
This is called from the
sleep opcode.Event Handling for Run-Loops
- opcode_t *Parrot_do_check_eventsExplicitly
- static void event_to_exceptionConvert event to exception and throw it.
- static opcode_t *do_eventRun user code or such.
The
- opcode_t *Parrot_do_handle_eventsCalled by the
sync called by the check_event opcode from run loops.
event argument is freed after execution.TODO: Instrument with splint args so splint knows event gets released.
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.
