You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@apr.apache.org by rb...@apache.org on 2001/09/01 09:13:37 UTC

cvs commit: apr/test testthread.c

rbb         01/09/01 00:13:37

  Modified:    test     testthread.c
  Log:
  After fighting the test build system on Windows for a while, this
  is a test for apr_thread_once that works on Windows.  I'll check it
  on Unix in a few minutes.
  
  Revision  Changes    Path
  1.23      +32 -0     apr/test/testthread.c
  
  Index: testthread.c
  ===================================================================
  RCS file: /home/cvs/apr/test/testthread.c,v
  retrieving revision 1.22
  retrieving revision 1.23
  diff -u -r1.22 -r1.23
  --- testthread.c	2001/08/22 15:40:29	1.22
  +++ testthread.c	2001/09/01 07:13:37	1.23
  @@ -81,12 +81,22 @@
   
   apr_lock_t *thread_lock;
   apr_pool_t *context;
  +apr_thread_once_t *control = NULL;
   int x = 0;
  +int value = 0;
   apr_status_t exit_ret_val = 123; /* just some made up number to check on later */
   
  +void init_func(void)
  +{
  +    value++;
  +}
  +
   void * APR_THREAD_FUNC thread_func1(apr_thread_t *thd, void *data)
   {
       int i;
  +
  +    apr_thread_once(control, init_func);
  +
       for (i = 0; i < 10000; i++) {
           apr_lock_acquire(thread_lock);
           x++;
  @@ -99,6 +109,9 @@
   void * APR_THREAD_FUNC thread_func2(apr_thread_t *thd, void *data)
   {
       int i;
  +
  +    apr_thread_once(control, init_func);
  +
       for (i = 0; i < 10000; i++) {
           apr_lock_acquire(thread_lock);
           x++;
  @@ -111,6 +124,9 @@
   void * APR_THREAD_FUNC thread_func3(apr_thread_t *thd, void *data)
   {
       int i;
  +
  +    apr_thread_once(control, init_func);
  +
       for (i = 0; i < 10000; i++) {
           apr_lock_acquire(thread_lock);
           x++;
  @@ -123,6 +139,9 @@
   void * APR_THREAD_FUNC thread_func4(apr_thread_t *thd, void *data)
   {
       int i;
  +
  +    apr_thread_once(control, init_func);
  +
       for (i = 0; i < 10000; i++) {
           apr_lock_acquire(thread_lock);
           x++;
  @@ -153,6 +172,8 @@
       }
       fprintf(stdout, "OK\n");
   
  +    apr_thread_once_init(&control, context);
  +
       fprintf(stdout, "Initializing the lock......."); 
       s1 = apr_lock_create(&thread_lock, APR_MUTEX, APR_INTRAPROCESS, "lock.file", context); 
       if (s1 != APR_SUCCESS) {
  @@ -201,6 +222,17 @@
       }
       else {
           fprintf(stdout, "Everything is working!\n");
  +    }
  +
  +    fprintf(stdout, "Checking if apr_thread_once worked.......");
  +    if (value != 1) {
  +        fflush(stdout);
  +        fprintf(stderr, "apr_thread_once must not have worked, "
  +                "value is %d\n", value);
  +        exit(-1);
  +    }
  +    else {
  +        fprintf(stdout, "apr_thread_once worked\n");
       }
       return 0;
   }