src/mutex.c
/**
 * Allocates and initializes a mutex with the PTHREAD_MUTEX_ERRORCHECK attribute
 * type.
 *
 * @return The allocated mutex or NULL if an error occurred.
 */
Allocates and initializes a mutex with the PTHREAD_MUTEX_ERRORCHECK attribute
type.

@return The allocated mutex or NULL if an error occurred.
Allocates and initializes a mutex with the PTHREAD_MUTEX_ERRORCHECK attribute type . @return The allocated mutex or NULL if an error occurred .
pthread_mutex_t* createMutex() {
    pthread_mutexattr_t *attribute = createMutexAttribute();
    if (NULL == attribute) {
	    printError(
		    0,
		    __FILE__,
		    __PRETTY_FUNCTION__,
		    "Could not create attribute."
	    );
        return NULL;
    }
    pthread_mutex_t *mutex = (pthread_mutex_t*) malloc(sizeof(pthread_mutex_t));
    if (NULL == mutex) {
	    printError(
		    errno,
		    __FILE__,
		    __PRETTY_FUNCTION__,
		    "Could not allocate memory for mutex."
	    );
        if (0 != destroyMutexAttribute(attribute)) {
            printError(0, __FILE__, __PRETTY_FUNCTION__, NULL);
        }
        return NULL;
    }
    if (0 != (errno = pthread_mutex_init(mutex, attribute))) {
	    printError(
		    errno,
		    __FILE__,
		    __PRETTY_FUNCTION__,
		    "Could not initialize mutex."
	    );
        if (0 != destroyMutexAttribute(attribute)) {
            printError(0, __FILE__, __PRETTY_FUNCTION__, NULL);
        }
        free(mutex);
        return NULL;
    }
    if (0 != destroyMutexAttribute(attribute)) {
	    printError(
		    0,
		    __FILE__,
		    __PRETTY_FUNCTION__,
		    NULL
	    );
        free(mutex);
        return NULL;
    }
    return mutex;
}
pthread_mutex_t * createMutex ( ) { pthread_mutexattr_t * attribute = createMutexAttribute ( ) ; if ( NULL == attribute ) { printError ( 0 , __FILE__ , __PRETTY_FUNCTION__ , " " ) ; return NULL ; } pthread_mutex_t * mutex = ( pthread_mutex_t * ) malloc ( sizeof ( pthread_mutex_t ) ) ; if ( NULL == mutex ) { printError ( errno , __FILE__ , __PRETTY_FUNCTION__ , " " ) ; if ( 0 != destroyMutexAttribute ( attribute ) ) { printError ( 0 , __FILE__ , __PRETTY_FUNCTION__ , NULL ) ; } return NULL ; } if ( 0 != ( errno = pthread_mutex_init ( mutex , attribute ) ) ) { printError ( errno , __FILE__ , __PRETTY_FUNCTION__ , " " ) ; if ( 0 != destroyMutexAttribute ( attribute ) ) { printError ( 0 , __FILE__ , __PRETTY_FUNCTION__ , NULL ) ; } free ( mutex ) ; return NULL ; } if ( 0 != destroyMutexAttribute ( attribute ) ) { printError ( 0 , __FILE__ , __PRETTY_FUNCTION__ , NULL ) ; free ( mutex ) ; return NULL ; } return mutex ; }
Allocates and initializes a mutex with the PTHREAD_MUTEX_ERRORCHECK attribute
 type.
Allocates and initializes a mutex with the PTHREAD_MUTEX_ERRORCHECK attribute type .