apr-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From wr...@apache.org
Subject svn commit: r585395 - /apr/apr-util/branches/1.2.x/test/testreslist.c
Date Wed, 17 Oct 2007 06:24:43 GMT
Author: wrowe
Date: Tue Oct 16 23:24:42 2007
New Revision: 585395

URL: http://svn.apache.org/viewvc?rev=585395&view=rev
Log:
Backport trunk changes for entropy - but this still infinitely loops.

Modified:
    apr/apr-util/branches/1.2.x/test/testreslist.c

Modified: apr/apr-util/branches/1.2.x/test/testreslist.c
URL: http://svn.apache.org/viewvc/apr/apr-util/branches/1.2.x/test/testreslist.c?rev=585395&r1=585394&r2=585395&view=diff
==============================================================================
--- apr/apr-util/branches/1.2.x/test/testreslist.c (original)
+++ apr/apr-util/branches/1.2.x/test/testreslist.c Tue Oct 16 23:24:42 2007
@@ -16,9 +16,14 @@
 
 #include <stdio.h>
 #include <stdlib.h>
+#include "apr_general.h"
 #include "apr_reslist.h"
 #include "apr_thread_proc.h"
-
+#if APR_HAVE_LIMITS_H
+#include <limits.h>
+#elif APR_HAVE_SYS_SYSLIMITS_H
+#include <sys/syslimits.h>
+#endif
 #if APR_HAVE_TIME_H
 #include <time.h>
 #endif /* APR_HAVE_TIME_H */
@@ -54,6 +59,15 @@
     int id;
 } my_resource_t;
 
+/* Linear congruential generator */
+static apr_uint32_t lgc(apr_uint32_t a)
+{
+    apr_uint64_t z = a;
+    z *= 279470273;
+    z %= APR_UINT64_C(4294967291);
+    return (apr_uint32_t)z;
+}
+
 static apr_status_t my_constructor(void **resource, void *params,
                                    apr_pool_t *pool)
 {
@@ -95,14 +109,19 @@
     apr_interval_time_t work_delay_sleep;
 } my_thread_info_t;
 
+#define PERCENT95th ( ( 2u^31 / 10u ) * 19u )
+
 static void * APR_THREAD_FUNC resource_consuming_thread(apr_thread_t *thd,
                                                         void *data)
 {
     apr_status_t rv;
     my_thread_info_t *thread_info = data;
     apr_reslist_t *rl = thread_info->reslist;
+    apr_uint32_t chance;
     int i;
 
+    apr_generate_random_bytes((void*)&chance, sizeof(chance));
+
     for (i = 0; i < CONSUMER_ITERATIONS; i++) {
         my_resource_t *res;
         void *vp;
@@ -116,17 +135,18 @@
         printf("  [tid:%d,iter:%d] using resource id:%d\n", thread_info->tid,
                i, res->id);
         apr_sleep(thread_info->work_delay_sleep);
-/* simulate a 5% chance of the resource being bad */
-        if ( drand48() < 0.95 ) {
-           rv = apr_reslist_release(rl, res);
+        /* simulate a 5% chance of the resource being bad */
+        chance = lgc(chance);
+        if ( chance < PERCENT95th ) {
+            rv = apr_reslist_release(rl, res);
             if (rv != APR_SUCCESS) {
                 fprintf(stderr, "Failed to return resource to reslist\n");
                 apr_thread_exit(thd, rv);
                 return NULL;
             }
        } else {
-           printf("invalidating resource id:%d\n", res->id) ;
-           rv = apr_reslist_invalidate(rl, res);
+            printf("invalidating resource id:%d\n", res->id) ;
+            rv = apr_reslist_invalidate(rl, res);
             if (rv != APR_SUCCESS) {
                 fprintf(stderr, "Failed to invalidate resource\n");
                 apr_thread_exit(thd, rv);
@@ -248,7 +268,6 @@
     int i;
     apr_thread_t *my_threads[CONSUMER_THREADS];
     my_thread_info_t my_thread_info[CONSUMER_THREADS];
-    srand48(time(0)) ;
 
     printf("Creating child pool.......................");
     rv = apr_pool_create(&pool, parpool);



Mime
View raw message