jerenkrantz 02/04/30 17:22:42 Modified: test testatomic.c Log: - Make this more legible (style police) - Modify output to indicate that the threads may take a while to complete (No compelling functional changes.) Revision Changes Path 1.15 +71 -53 apr/test/testatomic.c Index: testatomic.c =================================================================== RCS file: /home/cvs/apr/test/testatomic.c,v retrieving revision 1.14 retrieving revision 1.15 diff -u -r1.14 -r1.15 --- testatomic.c 18 Apr 2002 17:17:13 -0000 1.14 +++ testatomic.c 1 May 2002 00:22:42 -0000 1.15 @@ -83,58 +83,59 @@ static apr_status_t check_basic_atomics(volatile apr_atomic_t*p) { apr_uint32_t oldval; - apr_uint32_t casval=0; - apr_atomic_set(&y,2); + apr_uint32_t casval = 0; + apr_atomic_set(&y, 2); printf("%-60s", "testing apr_atomic_dec"); - if ( apr_atomic_dec(&y) == 0 ) { - fprintf(stderr, "Failed\noldval =%d should not be zero\n",apr_atomic_read(&y)); + if (apr_atomic_dec(&y) == 0) { + fprintf(stderr, "Failed\noldval =%d should not be zero\n", + apr_atomic_read(&y)); return APR_EGENERAL; } - if ( apr_atomic_dec(&y) != 0 ) { - fprintf(stderr, "Failed\noldval =%d should be zero\n",apr_atomic_read(&y)); + if (apr_atomic_dec(&y) != 0) { + fprintf(stderr, "Failed\noldval =%d should be zero\n", + apr_atomic_read(&y)); return APR_EGENERAL; } printf("OK\n"); printf("%-60s", "testing CAS"); - oldval = apr_atomic_cas(&casval,12,0); + oldval = apr_atomic_cas(&casval, 12, 0); if (oldval != 0) { - fprintf(stderr, "Failed\noldval =%d should be zero\n",oldval); + fprintf(stderr, "Failed\noldval =%d should be zero\n", oldval); return APR_EGENERAL; } printf("OK\n"); printf("%-60s", "testing CAS - match non-null"); - oldval = apr_atomic_cas(&casval,23,12); + oldval = apr_atomic_cas(&casval, 23, 12); if (oldval != 12) { fprintf(stderr, "Failed\noldval =%d should be 12 y=%d\n", - oldval, - casval); + oldval, casval); return APR_EGENERAL; } printf("OK\n"); printf("%-60s", "testing CAS - no match"); - oldval = apr_atomic_cas(&casval,23,12); - if (oldval != 23 ) { + oldval = apr_atomic_cas(&casval, 23, 12); + if (oldval != 23) { fprintf(stderr, "Failed\noldval =%d should be 23 y=%d\n", - oldval, - casval); + oldval, casval); return APR_EGENERAL; } printf("OK\n"); printf("%-60s", "testing add"); - apr_atomic_set(&y,23); - apr_atomic_add(&y,4); + apr_atomic_set(&y, 23); + apr_atomic_add(&y, 4); if (apr_atomic_read(&y) != 27) { - fprintf(stderr, "Failed\nAtomic Add doesn't add up ;( expected 27 got %d\n", - oldval); - exit(-1); + fprintf(stderr, + "Failed\nAtomic Add doesn't add up ;( expected 27 got %d\n", + oldval); + return APR_EGENERAL; } printf("OK\n"); printf("%-60s", "testing add/inc"); - apr_atomic_set(&y,0); - apr_atomic_add(&y,20); + apr_atomic_set(&y, 0); + apr_atomic_add(&y, 20); apr_atomic_inc(&y); if (apr_atomic_read(&y) != 21) { fprintf(stderr, "Failed.\natomics do not add up\n"); @@ -217,6 +218,7 @@ apr_thread_exit(thd, exit_ret_val); return NULL; } + void * APR_THREAD_FUNC thread_func_none(apr_thread_t *thd, void *data) { int i; @@ -240,15 +242,18 @@ apr_status_t s2[NUM_THREADS]; apr_status_t rv; int i; - int mutex=0; + int mutex; apr_initialize(); - if (argc==2 && argv[1][0]=='m') - mutex=1; + if (argc == 2 && argv[1][0] == 'm') { + mutex = 1; + } + else { + mutex = 0; + } - printf("APR Simple Thread Test\n======================\n\n"); - + printf("APR Atomic Test\n===============\n\n"); #if !(defined WIN32) && !(defined NETWARE) && !(defined __MVS__) pthread_setconcurrency(8); #endif @@ -262,7 +267,7 @@ apr_thread_once_init(&control, context); - if (mutex==1) { + if (mutex == 1) { printf("%-60s", "Initializing the lock"); rv = apr_thread_mutex_create(&thread_lock, APR_THREAD_MUTEX_DEFAULT, context); @@ -273,22 +278,28 @@ } printf("OK\n"); } - rv = apr_atomic_init( context); + printf("%-60s", "Initializing the atomics"); + rv = apr_atomic_init(context); + if (rv != APR_SUCCESS) { + fprintf(stderr, "Failed.\n"); + exit(-1); + } + printf("OK\n"); rv = check_basic_atomics(&y); if (rv != APR_SUCCESS) { fprintf(stderr, "Failed.\n"); exit(-1); } - apr_atomic_set(&y,0); + apr_atomic_set(&y, 0); printf("%-60s", "Starting all the threads"); - for (i=0;i