misc/lock-monitor/lock-monitor.c
static int known(const void *lock) {
    struct list *l;

    for (l = ordering; l; l = l->next) {
        if (l->value == lock)
            return 1;
    }
    return 0;
}
/* Check whether the lock given is already in the partial ordering (i.e.
 * whether we are already aware of it). It is assumed that the callee holds
 * ordering_lock when calling this function. It would have been possible to do
 * the ordering_lock locking and unlocking within this function, but this
 * doesn't actually work. We know that this function is called as a check
 * before calling add. Putting the locking inside here would leave a time
 * between calling known and add during which ordering_lock was not held. This
 * introduces a time-of-check-to-time-of-use problem. Consider the following:
 *   thread 1   thread 2
 *   --------   --------       Thread 1 and 2 can perform the known check for
 *    known?                   the same lock, get the same answer and then both
 *               known?        add this same lock. Hmm, lengthy comment for
 *                add          such a short function...
 *     add
 */
Check whether the lock given is already in the partial ordering . It is assumed that the callee holds
ordering_lock when calling this function. It would have been possible to do
the ordering_lock locking and unlocking within this function, but this
doesn't actually work. We know that this function is called as a check
before calling add. Putting the locking inside here would leave a time
between calling known and add during which ordering_lock was not held.
Check whether the lock given is already in the partial ordering . It is assumed that the callee holds ordering_lock when calling this function . It would have been possible to do the ordering_lock locking and unlocking within this function but this doesn ' t actually work . We know that this function is called as a check before calling add . Putting the locking inside here would leave a time between calling known and add during which ordering_lock was not held .
static int known(const void *lock) {
    struct list *l;
    for (l = ordering; l; l = l->next) {
        if (l->value == lock)
            return 1;
    }
    return 0;
}
static int known ( const void * lock ) { struct list * l ; for ( l = ordering ; l ; l = l -> next ) { if ( l -> value == lock ) return 1 ; } return 0 ; }
Check whether the lock given is already in the partial ordering (i.e.
Check whether the lock given is already in the partial ordering ( i . e .