apr-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From b..@apache.org
Subject cvs commit: apr/threadproc/os2 thread.c
Date Sun, 02 Sep 2001 05:20:49 GMT
bjh         01/09/01 22:20:49

  Modified:    threadproc/os2 thread.c
  Log:
  OS/2: Implement apr_thread_once().
  Avoids a race condition by using an OS/2 event semaphore, created in the
  posted state so that the first (and only the first) thread to reset it receives
  a post count of 1.
  
  Revision  Changes    Path
  1.28      +17 -2     apr/threadproc/os2/thread.c
  
  Index: thread.c
  ===================================================================
  RCS file: /home/cvs/apr/threadproc/os2/thread.c,v
  retrieving revision 1.27
  retrieving revision 1.28
  diff -u -r1.27 -r1.28
  --- thread.c	2001/08/31 06:49:54	1.27
  +++ thread.c	2001/09/02 05:20:49	1.28
  @@ -245,11 +245,26 @@
   APR_DECLARE(apr_status_t) apr_thread_once_init(apr_thread_once_t **control,
                                                  apr_pool_t *p)
   {
  -    return APR_ENOTIMPL;
  +    ULONG rc;
  +    *control = (apr_thread_once_t *)apr_pcalloc(p, sizeof(apr_thread_once_t));
  +    rc = DosCreateEventSem(NULL, &(*control)->sem, 0, TRUE);
  +    return APR_FROM_OS_ERROR(rc);
   }
   
  +
  +
   APR_DECLARE(apr_status_t) apr_thread_once(apr_thread_once_t *control, 
                                             void (*func)(void))
   {
  -    return APR_ENOTIMPL;
  +    if (!control->hit) {
  +        ULONG count, rc;
  +        rc = DosResetEventSem(control->sem, &count);
  +
  +        if (rc == 0 && count) {
  +            control->hit = 1;
  +            func();
  +        }
  +    }
  +
  +    return APR_SUCCESS;
   }
  
  
  

Mime
View raw message