Return-Path: Delivered-To: apmail-apr-commits-archive@www.apache.org Received: (qmail 97101 invoked from network); 5 Jul 2007 00:07:06 -0000 Received: from hermes.apache.org (HELO mail.apache.org) (140.211.11.2) by minotaur.apache.org with SMTP; 5 Jul 2007 00:07:06 -0000 Received: (qmail 14884 invoked by uid 500); 5 Jul 2007 00:07:09 -0000 Delivered-To: apmail-apr-commits-archive@apr.apache.org Received: (qmail 14853 invoked by uid 500); 5 Jul 2007 00:07:09 -0000 Mailing-List: contact commits-help@apr.apache.org; run by ezmlm Precedence: bulk List-Post: List-Help: List-Unsubscribe: Reply-To: dev@apr.apache.org List-Id: Delivered-To: mailing list commits@apr.apache.org Received: (qmail 14842 invoked by uid 99); 5 Jul 2007 00:07:08 -0000 Received: from herse.apache.org (HELO herse.apache.org) (140.211.11.133) by apache.org (qpsmtpd/0.29) with ESMTP; Wed, 04 Jul 2007 17:07:08 -0700 X-ASF-Spam-Status: No, hits=-99.5 required=10.0 tests=ALL_TRUSTED,NO_REAL_NAME X-Spam-Check-By: apache.org Received: from [140.211.11.3] (HELO eris.apache.org) (140.211.11.3) by apache.org (qpsmtpd/0.29) with ESMTP; Wed, 04 Jul 2007 17:07:05 -0700 Received: by eris.apache.org (Postfix, from userid 65534) id 179111A981A; Wed, 4 Jul 2007 17:06:45 -0700 (PDT) Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit Subject: svn commit: r553350 - /apr/apr/trunk/test/testatomic.c Date: Thu, 05 Jul 2007 00:06:44 -0000 To: commits@apr.apache.org From: davi@apache.org X-Mailer: svnmailer-1.1.0 Message-Id: <20070705000645.179111A981A@eris.apache.org> X-Virus-Checked: Checked by ClamAV on apache.org Author: davi Date: Wed Jul 4 17:06:44 2007 New Revision: 553350 URL: http://svn.apache.org/viewvc?view=rev&rev=553350 Log: Remove test code that is commented out. While at it, clean up the code a bit. Modified: apr/apr/trunk/test/testatomic.c Modified: apr/apr/trunk/test/testatomic.c URL: http://svn.apache.org/viewvc/apr/apr/trunk/test/testatomic.c?view=diff&rev=553350&r1=553349&r2=553350 ============================================================================== --- apr/apr/trunk/test/testatomic.c (original) +++ apr/apr/trunk/test/testatomic.c Wed Jul 4 17:06:44 2007 @@ -210,51 +210,38 @@ #if APR_HAS_THREADS -void * APR_THREAD_FUNC thread_func_mutex(apr_thread_t *thd, void *data); -void * APR_THREAD_FUNC thread_func_atomic(apr_thread_t *thd, void *data); -void * APR_THREAD_FUNC thread_func_none(apr_thread_t *thd, void *data); +void *APR_THREAD_FUNC thread_func_mutex(apr_thread_t *thd, void *data); +void *APR_THREAD_FUNC thread_func_atomic(apr_thread_t *thd, void *data); apr_thread_mutex_t *thread_lock; -volatile apr_uint32_t x = 0; /* mutex locks */ -volatile apr_uint32_t y = 0; /* atomic operations */ -volatile apr_uint32_t z = 0; /* no locks */ +volatile apr_uint32_t mutex_locks = 0; +volatile apr_uint32_t atomic_ops = 0; apr_status_t exit_ret_val = 123; /* just some made up number to check on later */ #define NUM_THREADS 40 #define NUM_ITERATIONS 20000 -void * APR_THREAD_FUNC thread_func_mutex(apr_thread_t *thd, void *data) +void *APR_THREAD_FUNC thread_func_mutex(apr_thread_t *thd, void *data) { int i; for (i = 0; i < NUM_ITERATIONS; i++) { apr_thread_mutex_lock(thread_lock); - x++; + mutex_locks++; apr_thread_mutex_unlock(thread_lock); } apr_thread_exit(thd, exit_ret_val); return NULL; -} - -void * APR_THREAD_FUNC thread_func_atomic(apr_thread_t *thd, void *data) -{ - int i; - - for (i = 0; i < NUM_ITERATIONS ; i++) { - apr_atomic_inc32(&y); - apr_atomic_add32(&y, 2); - apr_atomic_dec32(&y); - apr_atomic_dec32(&y); - } - apr_thread_exit(thd, exit_ret_val); - return NULL; } -void * APR_THREAD_FUNC thread_func_none(apr_thread_t *thd, void *data) +void *APR_THREAD_FUNC thread_func_atomic(apr_thread_t *thd, void *data) { int i; for (i = 0; i < NUM_ITERATIONS ; i++) { - z++; + apr_atomic_inc32(&atomic_ops); + apr_atomic_add32(&atomic_ops, 2); + apr_atomic_dec32(&atomic_ops); + apr_atomic_dec32(&atomic_ops); } apr_thread_exit(thd, exit_ret_val); return NULL; @@ -264,10 +251,6 @@ { apr_thread_t *t1[NUM_THREADS]; apr_thread_t *t2[NUM_THREADS]; - apr_thread_t *t3[NUM_THREADS]; - apr_status_t s1[NUM_THREADS]; - apr_status_t s2[NUM_THREADS]; - apr_status_t s3[NUM_THREADS]; apr_status_t rv; int i; @@ -279,34 +262,24 @@ APR_ASSERT_SUCCESS(tc, "Could not create lock", rv); for (i = 0; i < NUM_THREADS; i++) { - apr_status_t r1, r2, r3; + apr_status_t r1, r2; r1 = apr_thread_create(&t1[i], NULL, thread_func_mutex, NULL, p); r2 = apr_thread_create(&t2[i], NULL, thread_func_atomic, NULL, p); - r3 = apr_thread_create(&t3[i], NULL, thread_func_none, NULL, p); - ABTS_ASSERT(tc, "Failed creating threads", - r1 == APR_SUCCESS && r2 == APR_SUCCESS && - r3 == APR_SUCCESS); + ABTS_ASSERT(tc, "Failed creating threads", !r1 && !r2); } for (i = 0; i < NUM_THREADS; i++) { - apr_thread_join(&s1[i], t1[i]); - apr_thread_join(&s2[i], t2[i]); - apr_thread_join(&s3[i], t3[i]); - + apr_status_t s1, s2; + apr_thread_join(&s1, t1[i]); + apr_thread_join(&s2, t2[i]); + ABTS_ASSERT(tc, "Invalid return value from thread_join", - s1[i] == exit_ret_val && s2[i] == exit_ret_val && - s3[i] == exit_ret_val); + s1 == exit_ret_val && s2 == exit_ret_val); } - ABTS_INT_EQUAL(tc, x, NUM_THREADS * NUM_ITERATIONS); - ABTS_INT_EQUAL(tc, apr_atomic_read32(&y), NUM_THREADS * NUM_ITERATIONS); - /* Comment out this test, because I have no clue what this test is - * actually telling us. We are checking something that may or may not - * be true, and it isn't really testing APR at all. - ABTS_ASSERT(tc, "We expect this to fail, because we tried to update " - "an integer in a non-thread-safe manner.", - z != NUM_THREADS * NUM_ITERATIONS); - */ + ABTS_INT_EQUAL(tc, mutex_locks, NUM_THREADS * NUM_ITERATIONS); + ABTS_INT_EQUAL(tc, apr_atomic_read32(&atomic_ops), + NUM_THREADS * NUM_ITERATIONS); } #endif /* !APR_HAS_THREADS */