def is_locked(lock):
    """Return whether a lock is locked.

    Suppors :class:`Lock`, :class:`RLock`, :class:`threading.Lock` and
    :class:`threading.RLock` instances.
    """
    if hasattr(lock, 'locked'):
        return lock.locked()
    elif hasattr(lock, '_is_owned'):
        return lock._is_owned()
    else:
        raise TypeError('expecting Lock/RLock')
