Wrapped mutex lock / unlock functions into function rather than macro

This commit is contained in:
Fufu Fang 2019-09-01 21:36:58 +01:00
parent ed5457c76f
commit e06ea6dc06
No known key found for this signature in database
GPG Key ID: 0F6BB5EF6F8BB729
3 changed files with 26 additions and 21 deletions

View File

@ -5,7 +5,6 @@
#include <openssl/crypto.h>
#include <errno.h>
#include <pthread.h>
#include <string.h>
#include <stdio.h>
#include <unistd.h>

View File

@ -31,3 +31,25 @@ int64_t round_div(int64_t a, int64_t b)
{
return (a + (b / 2)) / b;
}
void PTHREAD_MUTEX_UNLOCK(pthread_mutex_t *x)
{
int i;
i = pthread_mutex_unlock(x);
if (i) {
fprintf(stderr, "pthread_mutex_unlock failed, %d, %s\n", i,
strerror(i));
exit(EXIT_FAILURE);
}
}
void PTHREAD_MUTEX_LOCK(pthread_mutex_t *x)
{
int i;
i = pthread_mutex_lock(x);
if (i) {
fprintf(stderr, "pthread_mutex_lock failed, %d, %s\n", i,
strerror(i));
exit(EXIT_FAILURE);
}
}

View File

@ -5,6 +5,7 @@
* \brief utility functions
*/
#include <pthread.h>
#include <stdint.h>
#include <stdlib.h>
@ -20,30 +21,13 @@
/**
* \brief wrapper for pthread_mutex_lock()
*/
#define PTHREAD_MUTEX_LOCK(x)\
({\
int i;\
i = pthread_mutex_lock(x);\
if (i) { \
fprintf(stderr, "pthread_mutex_lock failed, %d, %s\n", i, \
strerror(i));\
exit(EXIT_FAILURE);\
}\
})
void PTHREAD_MUTEX_LOCK(pthread_mutex_t *x);
/**
* \brief wrapper for pthread_mutex_unlock()
*/
#define PTHREAD_MUTEX_UNLOCK(x)\
({\
int i;\
i = pthread_mutex_unlock(x);\
if (i) { \
fprintf(stderr, "pthread_mutex_unlock failed, %d, %s\n", i, \
strerror(i));\
exit(EXIT_FAILURE);\
}\
})
void PTHREAD_MUTEX_UNLOCK(pthread_mutex_t *x);
/**
* \brief append a path