misc/lock-monitor/lock-monitor.c
static void unlock(const void *lock) {
    struct thread *t;
    struct list *l, *temp;

    assert(known(lock)); /* No need to lock, as we're not modifying. */

    t = find_thread();
    assert(t);

    for (l = t->locks, temp = NULL; l; l = l->next) {
        if (l->value == lock) {
            if (!temp) t->locks = l->next;
            else       temp->next = l->next;
            free(l);
            return;
        }
    }

    /* We didn't find the lock. */
    lock_monitor_exception("Lock Monitor: Thread %p attempted to unlock %p "
        "while not holding this lock.\n", (void*)t->thread, lock);
    /* Unreachable. */
}
/* The unlocking code is somewhat simpler because we don't need to do any
 * checks. If necessary you can modify this code to add checks to force the
 * order in which threads unlock variables.
 */
The unlocking code is somewhat simpler because we don't need to do any
checks. If necessary you can modify this code to add checks to force the
order in which threads unlock variables.
The unlocking code is somewhat simpler because we don ' t need to do any checks . If necessary you can modify this code to add checks to force the order in which threads unlock variables .
static void unlock(const void *lock) {
    struct thread *t;
    struct list *l, *temp;
    assert(known(lock)); 
    t = find_thread();
    assert(t);
    for (l = t->locks, temp = NULL; l; l = l->next) {
        if (l->value == lock) {
            if (!temp) t->locks = l->next;
            else       temp->next = l->next;
            free(l);
            return;
        }
    }
    lock_monitor_exception("Lock Monitor: Thread %p attempted to unlock %p "
        "while not holding this lock.\n", (void*)t->thread, lock);
}
static void unlock ( const void * lock ) { struct thread * t ; struct list * l , * temp ; assert ( known ( lock ) ) ; t = find_thread ( ) ; assert ( t ) ; for ( l = t -> locks , temp = NULL ; l ; l = l -> next ) { if ( l -> value == lock ) { if ( ! temp ) t -> locks = l -> next ; else temp -> next = l -> next ; free ( l ) ; return ; } } lock_monitor_exception ( " " " \n " , ( void * ) t -> thread , lock ) ; }
The unlocking code is somewhat simpler because we don't need to do any
 checks.
The unlocking code is somewhat simpler because we don ' t need to do any checks .
/* No need to lock, as we're not modifying. */ /* We didn't find the lock. */ /* Unreachable. */