safelock.c
/* Returns the current status of the lock in *inuse.
 *
 * Checks if there are recent lock owner(s) of the data_mutex and
 * owner_mutex lock that have crashed. In this case there is a chance
 * the Safelock data was being updated and cannot be trusted.
 *
 * May return EINVAL if the lock is corrupted. */
Returns the current status of the lock in *inuse.
Checks if there are recent lock owner(s) of the data_mutex and
owner_mutex lock that have crashed. In this case there is a chance
the Safelock data was being updated and cannot be trusted.

May return EINVAL if the lock is corrupted.
Returns the current status of the lock in * inuse . Checks if there are recent lock owner ( s ) of the data_mutex and owner_mutex lock that have crashed . In this case there is a chance the Safelock data was being updated and cannot be trusted . May return EINVAL if the lock is corrupted .
static int owner_mutex_in_use(safelock_t lock, int data_mutex_dirty,
                              int *inuse)
{
    lock_data_t *shared;
    int dirty;
    int err;
    assert(lock);
    assert(lock->shared);
    assert(inuse);
    shared = lock->shared;
    err = mutex_lock(&shared->owner_mutex, SAFELOCK_LOCK_TRY, &dirty);
    if (err == EBUSY || err == EDEADLK) {
        *inuse = 1;
        return 0;
    }
    if (err)
        return err;
    if (data_mutex_dirty && dirty)
        shared->data_valid = 0;
    NOFAIL(pthread_mutex_unlock(&shared->owner_mutex));
    *inuse = 0;
    return 0;
}
static int owner_mutex_in_use ( safelock_t lock , int data_mutex_dirty , int * inuse ) { lock_data_t * shared ; int dirty ; int err ; assert ( lock ) ; assert ( lock -> shared ) ; assert ( inuse ) ; shared = lock -> shared ; err = mutex_lock ( & shared -> owner_mutex , SAFELOCK_LOCK_TRY , & dirty ) ; if ( err == EBUSY || err == EDEADLK ) { * inuse = 1 ; return 0 ; } if ( err ) return err ; if ( data_mutex_dirty && dirty ) shared -> data_valid = 0 ; NOFAIL ( pthread_mutex_unlock ( & shared -> owner_mutex ) ) ; * inuse = 0 ; return 0 ; }
Returns the current status of the lock in *inuse.
Returns the current status of the lock in * inuse .
/* EBUSY: Someone else has the lock
         * EDEADLK: We have the lock */ /* The previous owner may have died holding both data_mutex and the
     * owner_mutex while locking or updating the safelock. Hence the data
     * protected by the data_mutex may have been corrupted. Tag safelock
     * data as undefined to ensure it is not trusted. */ /* Lock was not in use */