mirror of
https://github.com/asterisk/asterisk.git
synced 2025-10-26 22:30:28 +00:00
Code formatting cleanups in utils.c and include/asterisk/lock.h
git-svn-id: https://origsvn.digium.com/svn/asterisk/trunk@3278 65c4cc65-6c06-0410-ace0-fbb531ad65f3
This commit is contained in:
@@ -76,7 +76,7 @@ static inline int __ast_pthread_mutex_init_attr(char *filename, int lineno, char
|
||||
pthread_mutexattr_t *attr)
|
||||
{
|
||||
#ifdef AST_MUTEX_INIT_W_CONSTRUCTORS
|
||||
if((t->mutex) != ((pthread_mutex_t)PTHREAD_MUTEX_INITIALIZER)) {
|
||||
if ((t->mutex) != ((pthread_mutex_t)PTHREAD_MUTEX_INITIALIZER)) {
|
||||
fprintf(stderr, "%s line %d (%s): Error: mutex '%s' is already initialized.\n",
|
||||
filename, lineno, func, mutex_name);
|
||||
fprintf(stderr, "%s line %d (%s): Error: previously initialization of mutex '%s'.\n",
|
||||
@@ -95,7 +95,7 @@ static inline int __ast_pthread_mutex_init_attr(char *filename, int lineno, char
|
||||
}
|
||||
|
||||
static inline int __ast_pthread_mutex_init(char *filename, int lineno, char *func,
|
||||
char* mutex_name, ast_mutex_t *t)
|
||||
char *mutex_name, ast_mutex_t *t)
|
||||
{
|
||||
static pthread_mutexattr_t attr;
|
||||
pthread_mutexattr_init(&attr);
|
||||
@@ -107,17 +107,17 @@ static inline int __ast_pthread_mutex_init(char *filename, int lineno, char *fun
|
||||
#define ast_pthread_mutex_init(pmutex,attr) __ast_pthread_mutex_init_attr(__FILE__, __LINE__, __PRETTY_FUNCTION__, #pmutex, pmutex, attr)
|
||||
|
||||
static inline int __ast_pthread_mutex_destroy(char *filename, int lineno, char *func,
|
||||
char* mutex_name, ast_mutex_t *t)
|
||||
char *mutex_name, ast_mutex_t *t)
|
||||
{
|
||||
int res;
|
||||
#ifdef AST_MUTEX_INIT_W_CONSTRUCTORS
|
||||
if((t->mutex) == ((pthread_mutex_t)PTHREAD_MUTEX_INITIALIZER)) {
|
||||
if ((t->mutex) == ((pthread_mutex_t)PTHREAD_MUTEX_INITIALIZER)) {
|
||||
fprintf(stderr, "%s line %d (%s): Error: mutex '%s' is uninitialized.\n",
|
||||
filename, lineno, func, mutex_name);
|
||||
}
|
||||
#endif
|
||||
res = pthread_mutex_trylock(&t->mutex);
|
||||
switch( res ) {
|
||||
switch (res) {
|
||||
case 0:
|
||||
pthread_mutex_unlock(&t->mutex);
|
||||
break;
|
||||
@@ -182,7 +182,7 @@ static inline int __ast_pthread_mutex_lock(char *filename, int lineno, char *fun
|
||||
{
|
||||
int res;
|
||||
#if defined(AST_MUTEX_INIT_W_CONSTRUCTORS) || defined(AST_MUTEX_INIT_ON_FIRST_USE)
|
||||
if((t->mutex) == ((pthread_mutex_t)PTHREAD_MUTEX_INITIALIZER)) {
|
||||
if ((t->mutex) == ((pthread_mutex_t)PTHREAD_MUTEX_INITIALIZER)) {
|
||||
#ifdef AST_MUTEX_INIT_W_CONSTRUCTORS
|
||||
fprintf(stderr, "%s line %d (%s): Error: mutex '%s' is uninitialized.\n",
|
||||
filename, lineno, func, mutex_name);
|
||||
@@ -195,8 +195,8 @@ static inline int __ast_pthread_mutex_lock(char *filename, int lineno, char *fun
|
||||
time_t seconds seconds = time(NULL);
|
||||
do {
|
||||
res = pthread_mutex_trylock(&t->mutex);
|
||||
if(res == EBUSY) {
|
||||
if((time(NULL) - seconds) % 5) {
|
||||
if (res == EBUSY) {
|
||||
if ((time(NULL) - seconds) % 5) {
|
||||
fprintf(stderr, "%s line %d (%s): Deadlock? waited %d sec for mutex '%s'?\n",
|
||||
filename, lineno, func, (time(NULL) - seconds), mutex_name);
|
||||
fprintf(stderr, "%s line %d (%s): '%s' was locked here.\n",
|
||||
@@ -231,7 +231,7 @@ static inline int __ast_pthread_mutex_trylock(char *filename, int lineno, char *
|
||||
{
|
||||
int res;
|
||||
#if defined(AST_MUTEX_INIT_W_CONSTRUCTORS) || defined(AST_MUTEX_INIT_ON_FIRST_USE)
|
||||
if((t->mutex) == ((pthread_mutex_t)PTHREAD_MUTEX_INITIALIZER)) {
|
||||
if ((t->mutex) == ((pthread_mutex_t)PTHREAD_MUTEX_INITIALIZER)) {
|
||||
#ifdef AST_MUTEX_INIT_W_CONSTRUCTORS
|
||||
fprintf(stderr, "%s line %d (%s): Error: mutex '%s' is uninitialized.\n",
|
||||
filename, lineno, func, mutex_name);
|
||||
@@ -255,7 +255,7 @@ static inline int __ast_pthread_mutex_unlock(char *filename, int lineno, char *f
|
||||
char* mutex_name, ast_mutex_t *t) {
|
||||
int res;
|
||||
#ifdef AST_MUTEX_INIT_W_CONSTRUCTORS
|
||||
if((t->mutex) == ((pthread_mutex_t)PTHREAD_MUTEX_INITIALIZER)) {
|
||||
if ((t->mutex) == ((pthread_mutex_t)PTHREAD_MUTEX_INITIALIZER)) {
|
||||
fprintf(stderr, "%s line %d (%s): Error: mutex '%s' is uninitialized.\n",
|
||||
filename, lineno, func, mutex_name);
|
||||
}
|
||||
@@ -331,13 +331,13 @@ static void __attribute__ ((destructor)) fini_##mutex(void) \
|
||||
|
||||
static inline int ast_mutex_lock(ast_mutex_t *pmutex)
|
||||
{
|
||||
if(*pmutex == (ast_mutex_t)AST_MUTEX_KIND)
|
||||
if (*pmutex == (ast_mutex_t)AST_MUTEX_KIND)
|
||||
ast_mutex_init(pmutex);
|
||||
return pthread_mutex_lock(pmutex);
|
||||
}
|
||||
static inline int ast_mutex_trylock(ast_mutex_t *pmutex)
|
||||
{
|
||||
if(*pmutex == (ast_mutex_t)AST_MUTEX_KIND)
|
||||
if (*pmutex == (ast_mutex_t)AST_MUTEX_KIND)
|
||||
ast_mutex_init(pmutex);
|
||||
return pthread_mutex_trylock(pmutex);
|
||||
}
|
||||
@@ -354,7 +354,6 @@ static inline int ast_mutex_trylock(ast_mutex_t *pmutex)
|
||||
#define AST_MUTEX_DEFINE_STATIC(mutex) __AST_MUTEX_DEFINE(static,mutex)
|
||||
#define AST_MUTEX_DEFINE_EXPORTED(mutex) __AST_MUTEX_DEFINE(/**/,mutex)
|
||||
|
||||
|
||||
#define AST_MUTEX_INITIALIZER __use_AST_MUTEX_DEFINE_STATIC_rather_than_AST_MUTEX_INITIALIZER__
|
||||
|
||||
#define gethostbyname __gethostbyname__is__not__reentrant__use__ast_gethostbyname__instead__
|
||||
|
||||
24
utils.c
24
utils.c
@@ -160,18 +160,22 @@ static void *test_thread_body(void *data)
|
||||
{
|
||||
ast_mutex_lock(&test_lock);
|
||||
lock_count += 10;
|
||||
if(lock_count != 10) test_errors++;
|
||||
if (lock_count != 10)
|
||||
test_errors++;
|
||||
ast_mutex_lock(&test_lock);
|
||||
lock_count += 10;
|
||||
if(lock_count != 20) test_errors++;
|
||||
if (lock_count != 20)
|
||||
test_errors++;
|
||||
ast_mutex_lock(&test_lock2);
|
||||
ast_mutex_unlock(&test_lock);
|
||||
lock_count -= 10;
|
||||
if(lock_count != 10) test_errors++;
|
||||
if (lock_count != 10)
|
||||
test_errors++;
|
||||
ast_mutex_unlock(&test_lock);
|
||||
lock_count -= 10;
|
||||
ast_mutex_unlock(&test_lock2);
|
||||
if(lock_count != 0) test_errors++;
|
||||
if (lock_count != 0)
|
||||
test_errors++;
|
||||
return NULL;
|
||||
}
|
||||
|
||||
@@ -185,19 +189,23 @@ int test_for_thread_safety(void)
|
||||
pthread_create(&test_thread, NULL, test_thread_body, NULL);
|
||||
pthread_yield();
|
||||
usleep(100);
|
||||
if(lock_count != 2) test_errors++;
|
||||
if (lock_count != 2)
|
||||
test_errors++;
|
||||
ast_mutex_unlock(&test_lock);
|
||||
lock_count -= 1;
|
||||
pthread_yield();
|
||||
usleep(100);
|
||||
if(lock_count != 1) test_errors++;
|
||||
if (lock_count != 1)
|
||||
test_errors++;
|
||||
ast_mutex_unlock(&test_lock);
|
||||
lock_count -= 1;
|
||||
if(lock_count != 0) test_errors++;
|
||||
if (lock_count != 0)
|
||||
test_errors++;
|
||||
ast_mutex_unlock(&test_lock2);
|
||||
pthread_yield();
|
||||
usleep(100);
|
||||
if(lock_count != 0) test_errors++;
|
||||
if (lock_count != 0)
|
||||
test_errors++;
|
||||
pthread_join(test_thread, NULL);
|
||||
return(test_errors); /* return 0 on success. */
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user