httpd-cvs mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From stodd...@hyperreal.org
Subject cvs commit: apache-2.0/src/lib/apr/locks/win32 locks.c locks.h
Date Tue, 05 Oct 1999 01:07:58 GMT
stoddard    99/10/04 18:07:57

  Modified:    src/lib/apr/locks/win32 locks.c locks.h
  Log:
  1. Add Win32 CriticalSections for intra-process locking
  2. Another argument swap
  
  Revision  Changes    Path
  1.4       +50 -20    apache-2.0/src/lib/apr/locks/win32/locks.c
  
  Index: locks.c
  ===================================================================
  RCS file: /home/cvs/apache-2.0/src/lib/apr/locks/win32/locks.c,v
  retrieving revision 1.3
  retrieving revision 1.4
  diff -u -r1.3 -r1.4
  --- locks.c	1999/10/04 16:36:59	1.3
  +++ locks.c	1999/10/05 01:07:55	1.4
  @@ -68,32 +68,49 @@
       newlock = (struct lock_t *)ap_palloc(cont, sizeof(struct lock_t));
   
       newlock->cntxt = cont;
  -    newlock->fname = strdup(fname);
  -
  +    /* ToDo:  How to handle the case when no context is available? 
  +    *         How to cleanup the storage properly?
  +    */
  +    if (cont)
  +        newlock->fname = ap_pstrdup(cont, fname);
  +    else
  +        newlock->fname = strdup(fname);
  +    newlock->type = type;
  +    newlock->scope = scope;
       sec.nLength = sizeof(SECURITY_ATTRIBUTES);
       sec.lpSecurityDescriptor = NULL;
   
  -    if (type == APR_CROSS_PROCESS || type == APR_LOCKALL) {
  +    if (scope == APR_CROSS_PROCESS || scope == APR_LOCKALL) {
           sec.bInheritHandle = TRUE;
       }
       else {
           sec.bInheritHandle = FALSE;
       }
   
  -    newlock->mutex = CreateMutex(&sec, FALSE, fname);
  +    if (type == APR_INTRAPROCESS) {
  +        InitializeCriticalSection(&newlock->section);
  +    } else {
  +        newlock->mutex = CreateMutex(&sec, FALSE, fname);
  +    }
       *lock = newlock;
       return APR_SUCCESS;
   }
   
   ap_status_t ap_child_init_lock(struct lock_t **lock, ap_context_t *cont, char *fname)
   {
  +    /* This routine should not be called (and OpenMutex will fail if called) 
  +     * on a INTRAPROCESS lock
  +     */
       (*lock) = (struct lock_t *)ap_palloc(cont, sizeof(struct lock_t));
   
       if ((*lock) == NULL) {
           return APR_ENOMEM;
       }
  +    if (cont)
  +        (*lock)->fname = ap_pstrdup(cont, fname);
  +    else
  +        (*lock)->fname = strdup(fname);
   
  -    (*lock)->fname = strdup(fname);
       (*lock)->mutex = OpenMutex(MUTEX_ALL_ACCESS, TRUE, fname);
       
       if ((*lock)->mutex == NULL) {
  @@ -105,31 +122,44 @@
   ap_status_t ap_lock(struct lock_t *lock)
   {
       DWORD rv;
  -
  -    rv = WaitForSingleObject(lock->mutex, INFINITE);
  -
  -    if (rv == WAIT_OBJECT_0 || rv == WAIT_ABANDONED) {
  +    if (lock->type == APR_INTRAPROCESS) {
  +        EnterCriticalSection(&lock->section);
           return APR_SUCCESS;
  -    }
  -    if (rv == WAIT_TIMEOUT) {
  -        return APR_TIMEUP;
  -    }
  +    } else {
  +        rv = WaitForSingleObject(lock->mutex, INFINITE);
   
  +        if (rv == WAIT_OBJECT_0 || rv == WAIT_ABANDONED) {
  +            return APR_SUCCESS;
  +        }
  +        if (rv == WAIT_TIMEOUT) {
  +            return APR_TIMEUP;
  +        }
  +    }
       return APR_EEXIST;
   }
   
   ap_status_t ap_unlock(struct lock_t *lock)
   {
  -    if (ReleaseMutex(lock->mutex) == 0) {
  -        return APR_EEXIST;
  +    if (lock->type == APR_INTRAPROCESS) {
  +        LeaveCriticalSection(&lock->section);
  +        return APR_SUCCESS;
  +    } else {
  +        if (ReleaseMutex(lock->mutex) == 0) {
  +            return APR_EEXIST;
  +        }
       }
       return APR_SUCCESS;
   }
   
   ap_status_t ap_destroy_lock(struct lock_t *lock)
   {
  -    if (CloseHandle(lock->mutex) == 0) {
  -        return APR_EEXIST;
  +    if (lock->type == APR_INTRAPROCESS) {
  +        DeleteCriticalSection(&lock->section);
  +        return APR_SUCCESS;
  +    } else {
  +        if (CloseHandle(lock->mutex) == 0) {
  +            return APR_EEXIST;
  +        }
       }
       return APR_SUCCESS;
   }
  @@ -137,7 +167,7 @@
   ap_status_t ap_get_lockdata(struct lock_t *lock, char *key, void *data)
   {
       if (lock != NULL) {
  -        return ap_get_userdata(lock->cntxt, key, &data);
  +        return ap_get_userdata(&data, lock->cntxt, key);
       }
       else {
           data = NULL;
  @@ -166,8 +196,8 @@
       return APR_SUCCESS;
   }
   
  -ap_status_t ap_put_os_lock(ap_context_t *cont, struct lock_t **lock, 
  -                            ap_os_lock_t *thelock)
  +ap_status_t ap_put_os_lock(struct lock_t **lock, ap_os_lock_t *thelock, 
  +                           ap_context_t *cont)
   {
       if (cont == NULL) {
           return APR_ENOCONT;
  
  
  
  1.2       +3 -0      apache-2.0/src/lib/apr/locks/win32/locks.h
  
  Index: locks.h
  ===================================================================
  RCS file: /home/cvs/apache-2.0/src/lib/apr/locks/win32/locks.h,v
  retrieving revision 1.1
  retrieving revision 1.2
  diff -u -r1.1 -r1.2
  --- locks.h	1999/08/17 15:59:42	1.1
  +++ locks.h	1999/10/05 01:07:56	1.2
  @@ -59,7 +59,10 @@
   
   struct lock_t {
       ap_context_t *cntxt;
  +    ap_locktype_e type;
  +    ap_lockscope_e scope;
       HANDLE mutex;
  +    CRITICAL_SECTION section;
       char *fname;
   };
   
  
  
  

Mime
View raw message