src/mutex.c
/**
 * Destroys and frees a mutex.
 *
 * @param mutex A mutex.
 * @return 0 if successful or 1 if an error occurred.
 */
Destroys and frees a mutex.
@param mutex A mutex.
@return 0 if successful or 1 if an error occurred.
Destroys and frees a mutex . @param mutex A mutex . @return 0 if successful or 1 if an error occurred .
int destroyMutex(pthread_mutex_t * mutex) {
    if (NULL == mutex) {
	    printError(
		    0,
		    __FILE__,
		    __PRETTY_FUNCTION__,
		    "Could not destroy mutex as it is null."
	    );
        return 1;
    }
    if (0 != (errno = pthread_mutex_trylock(mutex))) {
	    printError(
		    errno,
		    __FILE__,
		    __PRETTY_FUNCTION__,
		    "Could not destroy mutex as it is locked."
	    );
        return 1;
    }
    if (0 != unlockMutex(mutex)) {
	    printError(
		    0,
		    __FILE__,
		    __PRETTY_FUNCTION__,
		    NULL
	    );
        return 1;
    }
    if (0 != (errno = pthread_mutex_destroy(mutex))) {
	    printError(
		    errno,
		    __FILE__,
		    __PRETTY_FUNCTION__,
		    "Could not destroy mutex."
	    );
        return 1;
    }
    free(mutex);
    return 0;
}
int destroyMutex ( pthread_mutex_t * mutex ) { if ( NULL == mutex ) { printError ( 0 , __FILE__ , __PRETTY_FUNCTION__ , " " ) ; return 1 ; } if ( 0 != ( errno = pthread_mutex_trylock ( mutex ) ) ) { printError ( errno , __FILE__ , __PRETTY_FUNCTION__ , " " ) ; return 1 ; } if ( 0 != unlockMutex ( mutex ) ) { printError ( 0 , __FILE__ , __PRETTY_FUNCTION__ , NULL ) ; return 1 ; } if ( 0 != ( errno = pthread_mutex_destroy ( mutex ) ) ) { printError ( errno , __FILE__ , __PRETTY_FUNCTION__ , " " ) ; return 1 ; } free ( mutex ) ; return 0 ; }
Destroys and frees a mutex.
Destroys and frees a mutex .
/**
     * Destroying a locked mutex is undefined behaviour, so we must check if it
     * is locked.
     *
     * Sources
     *      * https://linux.die.net/man/3/pthread_mutex_destroy
     *      * https://linux.die.net/man/3/pthread_mutex_trylock
     */