mirror of
https://github.com/asterisk/asterisk.git
synced 2025-11-07 18:38:02 +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:
84
utils.c
84
utils.c
@@ -158,46 +158,54 @@ static int test_errors = 0;
|
||||
|
||||
static void *test_thread_body(void *data)
|
||||
{
|
||||
ast_mutex_lock(&test_lock);
|
||||
lock_count += 10;
|
||||
if(lock_count != 10) test_errors++;
|
||||
ast_mutex_lock(&test_lock);
|
||||
lock_count += 10;
|
||||
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++;
|
||||
ast_mutex_unlock(&test_lock);
|
||||
lock_count -= 10;
|
||||
ast_mutex_unlock(&test_lock2);
|
||||
if(lock_count != 0) test_errors++;
|
||||
return NULL;
|
||||
ast_mutex_lock(&test_lock);
|
||||
lock_count += 10;
|
||||
if (lock_count != 10)
|
||||
test_errors++;
|
||||
ast_mutex_lock(&test_lock);
|
||||
lock_count += 10;
|
||||
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++;
|
||||
ast_mutex_unlock(&test_lock);
|
||||
lock_count -= 10;
|
||||
ast_mutex_unlock(&test_lock2);
|
||||
if (lock_count != 0)
|
||||
test_errors++;
|
||||
return NULL;
|
||||
}
|
||||
|
||||
int test_for_thread_safety(void)
|
||||
{
|
||||
ast_mutex_lock(&test_lock2);
|
||||
ast_mutex_lock(&test_lock);
|
||||
lock_count += 1;
|
||||
ast_mutex_lock(&test_lock);
|
||||
lock_count += 1;
|
||||
pthread_create(&test_thread, NULL, test_thread_body, NULL);
|
||||
pthread_yield();
|
||||
usleep(100);
|
||||
if(lock_count != 2) test_errors++;
|
||||
ast_mutex_unlock(&test_lock);
|
||||
lock_count -= 1;
|
||||
pthread_yield();
|
||||
usleep(100);
|
||||
if(lock_count != 1) test_errors++;
|
||||
ast_mutex_unlock(&test_lock);
|
||||
lock_count -= 1;
|
||||
if(lock_count != 0) test_errors++;
|
||||
ast_mutex_unlock(&test_lock2);
|
||||
pthread_yield();
|
||||
usleep(100);
|
||||
if(lock_count != 0) test_errors++;
|
||||
pthread_join(test_thread, NULL);
|
||||
return(test_errors); /* return 0 on success. */
|
||||
ast_mutex_lock(&test_lock2);
|
||||
ast_mutex_lock(&test_lock);
|
||||
lock_count += 1;
|
||||
ast_mutex_lock(&test_lock);
|
||||
lock_count += 1;
|
||||
pthread_create(&test_thread, NULL, test_thread_body, NULL);
|
||||
pthread_yield();
|
||||
usleep(100);
|
||||
if (lock_count != 2)
|
||||
test_errors++;
|
||||
ast_mutex_unlock(&test_lock);
|
||||
lock_count -= 1;
|
||||
pthread_yield();
|
||||
usleep(100);
|
||||
if (lock_count != 1)
|
||||
test_errors++;
|
||||
ast_mutex_unlock(&test_lock);
|
||||
lock_count -= 1;
|
||||
if (lock_count != 0)
|
||||
test_errors++;
|
||||
ast_mutex_unlock(&test_lock2);
|
||||
pthread_yield();
|
||||
usleep(100);
|
||||
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