src/events.c - Event handling stuff
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.
static void sig_handler
- Handle signal
signum
.
- TODO - Only
SIGHUP
is handled at the moment for testing
static void 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.
static void Parrot_unblock_signal
- unblock a signal
void Parrot_init_signals
- Set up actions to handle signals.
Only SIGHUP handled at the moment.
static void init_events_first
- Init event system for first interpreter.
static void init_events_all
- Init events for all interpreters.
void Parrot_init_events
- Initialize the event system.
void Parrot_schedule_event
- Create queue entry and insert event into task queue.
static void schedule_signal_event
- create and schedule a signal event
void Parrot_new_timer_event
- Create a new timer event due at
diff
from now,
repeated at interval
and running the passed sub
.
void Parrot_new_cb_event
- Prepare and schedule a callback event.
void Parrot_del_timer_event
- Deactivate the timer identified by
timer
.
void Parrot_new_terminate_event
- Create a terminate event,
interpreter will leave the run-loop when this event arrives.
void 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.
void Parrot_kill_event_loop
- Schedule event-loop terminate event.
This shuts down the event thread.
void Parrot_schedule_interp_qentry
- Put a queue entry into the interpreters task queue and enable event checking for the interpreter.
void Parrot_schedule_broadcast_qentry
- Broadcast an event.
static void store_io_event
- Stores an event in the event stack.
Allocates memory if necessary.
static void io_thread_ready_rd
- Takes 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_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.
static void stop_io_thread
- Tell the IO thread to stop.
void Parrot_event_add_io_event
- Create new i/o event.
static QUEUE_ENTRY *dup_entry
- Duplicate queue entry.
static QUEUE_ENTRY *dup_entry_interval
- Duplicate timed entry and add interval to
abs_time
.
static int process_events
- Do something,
when an event arrived caller has locked the mutex returns 0 if event thread terminates.
static void *event_thread
- The event thread is started by the first interpreter.
It handles all events for all interpreters.
static opcode_t *wait_for_wakeup
- Sleep 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_event
- Go to sleep.
This is called from the
sleep
opcode.
opcode_t *Parrot_do_check_events
- Explicitly
sync
called by the check_event opcode from run loops.
static void event_to_exception
- Convert event to exception and throw it.
static opcode_t *do_event
- Run user code or such.
The
event
argument is freed after execution.
- TODO: Instrument with splint args so splint knows event gets released.
opcode_t *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
.
include/parrot/events.h and docs/dev/events.pod.