Hi, I realised that the guts of interrupt_register() needs to be done in irqhelp_server_loop() to configure the interrupt thread.
This means we need a semaphore to wait until the server loop is ready to execute, and a new api call irqhelp_wait_init() to allow the caller to wait after registering the handler and kicking off the server loop, to continue executing the main thread. On 5/7/23 17:59, Damien Zammit wrote: > +static struct irq * > +interrupt_register(int gsi, > + int bus, > + int dev, > + int fun, > + void (*handler)(void *), > + void *context) > +{ ... > + > + err = mach_port_allocate (mach_task_self (), MACH_PORT_RIGHT_RECEIVE, > + &delivery_port); > + if (err) > + goto fail; > + > + irq->port = delivery_port; > + > + err = thread_get_assignment (mach_thread_self (), &pset); > + if (err) > + goto fail; > + > + err = host_processor_set_priv (master_host, pset, &psetcntl); > + if (err) > + goto fail; > + > + thread_max_priority (mach_thread_self (), psetcntl, 0); > + err = thread_priority (mach_thread_self (), IRQ_THREAD_PRIORITY, 0); > + if (err) > + goto fail; > + > + err = device_intr_register(irqdev, irq->gsi, > + 0, irq->port, > + MACH_MSG_TYPE_MAKE_SEND); > + if (err) > + goto fail; > + > + return irq; > + > +fail: > + printf("irqhelp failed to register irq %d\n", gsi); > + pthread_cond_destroy(&irq->irqcond); > + pthread_mutex_destroy(&irq->irqlock); > + free(irq); > + return NULL; > +} Damien