You are viewing a plain text version of this content. The canonical link for it is here.
Posted to cvs@httpd.apache.org by bj...@locus.apache.org on 2000/03/03 15:01:08 UTC
cvs commit: apache-2.0/src/lib/apr/locks/os2 locks.h locks.c
bjh 00/03/03 06:01:08
Modified: src/lib/apr/locks/os2 locks.h locks.c
Log:
OS/2: Rework of mutex locks. Makes it safe to use the same object in multiple
threads while protecting against a moderately obscure problem where multiple
handles to the same named mutex in the SAME THREAD behave as if they were the
same handle.
IE calling lock on one handle & unlock on another would result in the mutex
not being owned by the thread.
Revision Changes Path
1.2 +5 -1 apache-2.0/src/lib/apr/locks/os2/locks.h
Index: locks.h
===================================================================
RCS file: /home/cvs/apache-2.0/src/lib/apr/locks/os2/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 2000/03/03 14:01:07 1.2
@@ -63,10 +63,14 @@
struct lock_t {
ap_context_t *cntxt;
ap_locktype_e type;
- int curr_locked;
char *fname;
HMTX hMutex;
+ TID owner;
+ int lock_count;
+ TIB *tib;
};
+
+void setup_lock();
#endif /* LOCKS_H */
1.6 +54 -18 apache-2.0/src/lib/apr/locks/os2/locks.c
Index: locks.c
===================================================================
RCS file: /home/cvs/apache-2.0/src/lib/apr/locks/os2/locks.c,v
retrieving revision 1.5
retrieving revision 1.6
diff -u -r1.5 -r1.6
--- locks.c 1999/10/29 07:17:16 1.5
+++ locks.c 2000/03/03 14:01:07 1.6
@@ -61,8 +61,16 @@
#define INCL_DOS
#include <os2.h>
+#define CurrentTid (lock->tib->tib_ptib2->tib2_ultid)
-ap_status_t lock_cleanup(void *thelock)
+
+void setup_lock()
+{
+}
+
+
+
+static ap_status_t lock_cleanup(void *thelock)
{
struct lock_t *lock = thelock;
return ap_destroy_lock(lock);
@@ -75,12 +83,15 @@
struct lock_t *new;
ULONG rc;
char *semname;
+ PIB *ppib;
new = (struct lock_t *)ap_palloc(cont, sizeof(struct lock_t));
new->cntxt = cont;
new->type = type;
- new->curr_locked = 0;
+ new->owner = 0;
+ new->lock_count = 0;
new->fname = ap_pstrdup(cont, fname);
+ DosGetInfoBlocks(&(new->tib), &ppib);
if (fname == NULL)
semname = NULL;
@@ -89,6 +100,33 @@
rc = DosCreateMutexSem(semname, &(new->hMutex), type == APR_CROSS_PROCESS ? DC_SEM_SHARED : 0, FALSE);
*lock = new;
+
+ if (!rc)
+ ap_register_cleanup(cont, new, lock_cleanup, ap_null_cleanup);
+
+ return os2errno(rc);
+}
+
+
+
+ap_status_t ap_child_init_lock(ap_lock_t **lock, char *fname, ap_context_t *cont)
+{
+ int rc;
+ PIB *ppib;
+
+ *lock = (struct lock_t *)ap_palloc(cont, sizeof(struct lock_t));
+
+ if (lock == NULL)
+ return APR_ENOMEM;
+
+ DosGetInfoBlocks(&((*lock)->tib), &ppib);
+ (*lock)->owner = 0;
+ (*lock)->lock_count = 0;
+ rc = DosOpenMutexSem( fname, &(*lock)->hMutex );
+
+ if (!rc)
+ ap_register_cleanup(cont, *lock, lock_cleanup, ap_null_cleanup);
+
return os2errno(rc);
}
@@ -98,16 +136,14 @@
{
ULONG rc;
- if (!lock->curr_locked) {
- rc = DosRequestMutexSem(lock->hMutex, SEM_INDEFINITE_WAIT);
+ rc = DosRequestMutexSem(lock->hMutex, SEM_INDEFINITE_WAIT);
- if (rc == 0)
- lock->curr_locked = TRUE;
-
- return os2errno(rc);
+ if (rc == 0) {
+ lock->owner = CurrentTid;
+ lock->lock_count++;
}
-
- return APR_SUCCESS;
+
+ return os2errno(rc);
}
@@ -116,12 +152,9 @@
{
ULONG rc;
- if (lock->curr_locked) {
+ if (lock->owner == CurrentTid && lock->lock_count > 0) {
+ lock->lock_count--;
rc = DosReleaseMutexSem(lock->hMutex);
-
- if (rc == 0)
- lock->curr_locked = FALSE;
-
return os2errno(rc);
}
@@ -133,10 +166,13 @@
ap_status_t ap_destroy_lock(struct lock_t *lock)
{
ULONG rc;
- ap_status_t stat;
+ ap_status_t stat = APR_SUCCESS;
- stat = ap_unlock(lock);
-
+ if (lock->owner == CurrentTid) {
+ while (lock->lock_count > 0 && stat == APR_SUCCESS)
+ stat = ap_unlock(lock);
+ }
+
if (stat != APR_SUCCESS)
return stat;