|parrotcode: Event handling stuff
Contents | C
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
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
- 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
- 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.
- Initialize the event system.
- Create queue entry and insert event into task queue.
static void schedule_signal_event
- create and schedule a signal event
- Create a new timer event due at
diff from now,
interval and running the passed
- Prepare and schedule a callback event.
- Deactivate the timer identified by
- Create a terminate event,
interpreter will leave the run-loop when this event arrives.
- Create a suspend-for-GC event,
interpreter will wait on a condition variable for GC to finish when the event arrives.
- Schedule event-loop terminate event.
This shuts down the event thread.
- Put a queue entry into the interpreters task queue and enable event checking for the interpreter.
- 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.
- 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
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.
- Go to sleep.
This is called from the
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.
event argument is freed after execution.
- TODO: Instrument with splint args so splint knows event gets released.
- Called by the
check_event__ opcode from run loops or from above.
When called from the
we have to restore the
include/parrot/events.h and docs/dev/events.pod.