bjh 99/06/06 00:51:13
Modified: apr/locks/os2 locks.c Log: Register cleanup for a lock. Improve logic of lock/unlock. Revision Changes Path 1.2 +40 -16 apache-apr/apr/locks/os2/locks.c Index: locks.c =================================================================== RCS file: /home/cvs/apache-apr/apr/locks/os2/locks.c,v retrieving revision 1.1 retrieving revision 1.2 diff -u -r1.1 -r1.2 --- locks.c 1999/06/04 16:40:09 1.1 +++ locks.c 1999/06/06 07:51:12 1.2 @@ -56,10 +56,20 @@ #include "apr_general.h" #include "apr_lib.h" #include "locks.h" +#include "fileio.h" #include <string.h> #define INCL_DOS #include <os2.h> + +ap_status_t lock_cleanup(void *thelock) +{ + struct lock_t *lock = thelock; + return ap_destroy_lock(lock); +} + + + ap_status_t ap_create_lock(ap_context_t *cont, ap_locktype_e type, char *fname, struct lock_t **lock) { struct lock_t *new; @@ -82,12 +92,17 @@ ap_status_t ap_lock(struct lock_t *lock) { ULONG rc; - rc = DosRequestMutexSem(lock->hMutex, SEM_INDEFINITE_WAIT); + + if (!lock->curr_locked) { + rc = DosRequestMutexSem(lock->hMutex, SEM_INDEFINITE_WAIT); - if (rc == 0) - lock->curr_locked = TRUE; + if (rc == 0) + lock->curr_locked = TRUE; - return os2errno(rc); + return os2errno(rc); + } + + return APR_SUCCESS; } @@ -95,12 +110,17 @@ ap_status_t ap_unlock(struct lock_t *lock) { ULONG rc; - rc = DosReleaseMutexSem(lock->hMutex); + + if (lock->curr_locked) { + rc = DosReleaseMutexSem(lock->hMutex); - if (rc == 0) - lock->curr_locked = FALSE; + if (rc == 0) + lock->curr_locked = FALSE; - return os2errno(rc); + return os2errno(rc); + } + + return APR_SUCCESS; } @@ -108,16 +128,20 @@ ap_status_t ap_destroy_lock(struct lock_t *lock) { ULONG rc; + ap_status_t stat; - if (lock->curr_locked) { - rc = DosReleaseMutexSem(lock->hMutex); + stat = ap_unlock(lock); + + if (stat != APR_SUCCESS) + return stat; + + if (lock->hMutex == 0) + return APR_SUCCESS; - if (rc) - return os2errno(rc); - } - rc = DosCloseMutexSem(lock->hMutex); + + if (!rc) + lock->hMutex = 0; + return os2errno(rc); } - -