Formatted all code using indent

This commit is contained in:
Patrick J Cherry
2018-02-20 10:05:35 +00:00
parent 19a1127bde
commit f47f56d4c4
59 changed files with 7631 additions and 7762 deletions

View File

@@ -4,72 +4,70 @@
#include <pthread.h>
struct flexthread_mutex * flexthread_mutex_create(void)
struct flexthread_mutex *flexthread_mutex_create(void)
{
struct flexthread_mutex * ftm =
xmalloc( sizeof( struct flexthread_mutex ) );
struct flexthread_mutex *ftm =
xmalloc(sizeof(struct flexthread_mutex));
FATAL_UNLESS( 0 == pthread_mutex_init( &ftm->mutex, NULL ),
"Mutex initialisation failed" );
return ftm;
FATAL_UNLESS(0 == pthread_mutex_init(&ftm->mutex, NULL),
"Mutex initialisation failed");
return ftm;
}
void flexthread_mutex_destroy( struct flexthread_mutex * ftm )
void flexthread_mutex_destroy(struct flexthread_mutex *ftm)
{
NULLCHECK( ftm );
NULLCHECK(ftm);
if( flexthread_mutex_held( ftm ) ) {
flexthread_mutex_unlock( ftm );
}
else if ( (pthread_t)NULL != ftm->holder ) {
/* This "should never happen": if we can try to destroy
* a mutex currently held by another thread, there's a
* logic bug somewhere. I know the test here is racy,
* but there's not a lot we can do about it at this
* point.
*/
fatal( "Attempted to destroy a flexthread_mutex"\
" held by another thread!" );
}
if (flexthread_mutex_held(ftm)) {
flexthread_mutex_unlock(ftm);
} else if ((pthread_t) NULL != ftm->holder) {
/* This "should never happen": if we can try to destroy
* a mutex currently held by another thread, there's a
* logic bug somewhere. I know the test here is racy,
* but there's not a lot we can do about it at this
* point.
*/
fatal("Attempted to destroy a flexthread_mutex"
" held by another thread!");
}
FATAL_UNLESS( 0 == pthread_mutex_destroy( &ftm->mutex ),
"Mutex destroy failed" );
free( ftm );
FATAL_UNLESS(0 == pthread_mutex_destroy(&ftm->mutex),
"Mutex destroy failed");
free(ftm);
}
int flexthread_mutex_lock( struct flexthread_mutex * ftm )
int flexthread_mutex_lock(struct flexthread_mutex *ftm)
{
NULLCHECK( ftm );
NULLCHECK(ftm);
int failure = pthread_mutex_lock( &ftm->mutex );
if ( 0 == failure ) {
ftm->holder = pthread_self();
}
int failure = pthread_mutex_lock(&ftm->mutex);
if (0 == failure) {
ftm->holder = pthread_self();
}
return failure;
return failure;
}
int flexthread_mutex_unlock( struct flexthread_mutex * ftm )
int flexthread_mutex_unlock(struct flexthread_mutex *ftm)
{
NULLCHECK( ftm );
NULLCHECK(ftm);
pthread_t orig = ftm->holder;
ftm->holder = (pthread_t)NULL;
int failure = pthread_mutex_unlock( &ftm->mutex );
if ( 0 != failure ) {
ftm->holder = orig;
}
return failure;
pthread_t orig = ftm->holder;
ftm->holder = (pthread_t) NULL;
int failure = pthread_mutex_unlock(&ftm->mutex);
if (0 != failure) {
ftm->holder = orig;
}
return failure;
}
int flexthread_mutex_held( struct flexthread_mutex * ftm )
int flexthread_mutex_held(struct flexthread_mutex *ftm)
{
NULLCHECK( ftm );
return pthread_self() == ftm->holder;
NULLCHECK(ftm);
return pthread_self() == ftm->holder;
}