import hashlib


def generate_mutex_name(target_name, prefix=""):
    """
    A mutex name must be a valid filesystem path, so, this generates a hash
    that can be used in case the original name would have conflicts.
    """

    if not isinstance(target_name, bytes):
        target_name = target_name.encode("utf-8")

    return prefix + (hashlib.sha224(target_name).hexdigest()[:16])