Changeset b14e35f2 in mainline for kernel/generic/src/ipc/irq.c


Ignore:
Timestamp:
2006-10-17T21:20:00Z (18 years ago)
Author:
Jakub Jermar <jakub@…>
Branches:
lfn, master, serial, ticket/834-toolchain-update, topic/msim-upgrade, topic/simplify-dev-export
Children:
fb8335c
Parents:
4874c2d
Message:

Implement efficient IPC notification cleanup.

File:
1 edited

Legend:

Unmodified
Added
Removed
  • kernel/generic/src/ipc/irq.c

    r4874c2d rb14e35f2  
    177177        if (irq) {
    178178                if (irq->notif_cfg.answerbox == box) {
     179                        code_free(irq->notif_cfg.code);
    179180                        irq->notif_cfg.notify = false;
    180181                        irq->notif_cfg.answerbox = NULL;
     
    182183                        irq->notif_cfg.method = 0;
    183184                        irq->notif_cfg.counter = 0;
    184                         code_free(irq->notif_cfg.code);
     185
     186                        spinlock_lock(&box->irq_lock);
     187                        list_remove(&irq->notif_cfg.link);
     188                        spinlock_unlock(&box->irq_lock);
     189                       
    185190                        spinlock_unlock(&irq->lock);
    186191                }
     
    199204 * @return EBADMEM, ENOENT or EEXISTS on failure or 0 on success.
    200205 */
    201 int
    202 ipc_irq_register(answerbox_t *box, inr_t inr, devno_t devno, unative_t method, irq_code_t *ucode)
     206int ipc_irq_register(answerbox_t *box, inr_t inr, devno_t devno, unative_t method, irq_code_t *ucode)
    203207{
    204208        ipl_t ipl;
     
    233237        irq->notif_cfg.code = code;
    234238        irq->notif_cfg.counter = 0;
     239
     240        spinlock_lock(&box->irq_lock);
     241        list_append(&irq->notif_cfg.link, &box->irq_head);
     242        spinlock_unlock(&box->irq_lock);
     243
    235244        spinlock_unlock(&irq->lock);
    236245        interrupts_restore(ipl);
     
    311320/** Disconnect all IRQ notifications from an answerbox.
    312321 *
     322 * This function is effective because the answerbox contains
     323 * list of all irq_t structures that are registered to
     324 * send notifications to it.
     325 *
    313326 * @param box Answerbox for which we want to carry out the cleanup.
    314327 */
    315328void ipc_irq_cleanup(answerbox_t *box)
    316329{
    317         /* TODO */
     330        ipl_t ipl;
     331       
     332loop:
     333        ipl = interrupts_disable();
     334        spinlock_lock(&box->irq_lock);
     335       
     336        while (box->irq_head.next != &box->irq_head) {
     337                link_t *cur = box->irq_head.next;
     338                irq_t *irq;
     339               
     340                irq = list_get_instance(cur, irq_t, notif_cfg.link);
     341                if (!spinlock_trylock(&irq->lock)) {
     342                        /*
     343                         * Avoid deadlock by trying again.
     344                         */
     345                        spinlock_unlock(&box->irq_lock);
     346                        interrupts_restore(ipl);
     347                        goto loop;
     348                }
     349               
     350                ASSERT(irq->notif_cfg.answerbox == box);
     351               
     352                list_remove(&irq->notif_cfg.link);
     353               
     354                /*
     355                 * Don't forget to free any top-half pseudocode.
     356                 */
     357                code_free(irq->notif_cfg.code);
     358               
     359                irq->notif_cfg.notify = false;
     360                irq->notif_cfg.answerbox = NULL;
     361                irq->notif_cfg.code = NULL;
     362                irq->notif_cfg.method = 0;
     363                irq->notif_cfg.counter = 0;
     364
     365                spinlock_unlock(&irq->lock);
     366        }
     367       
     368        spinlock_unlock(&box->irq_lock);
     369        interrupts_restore(ipl);
    318370}
    319371
Note: See TracChangeset for help on using the changeset viewer.