summaryrefslogtreecommitdiff
path: root/locks/win32
diff options
context:
space:
mode:
authorstoddard <stoddard@13f79535-47bb-0310-9956-ffa450edef68>1999-10-05 01:07:56 +0000
committerstoddard <stoddard@13f79535-47bb-0310-9956-ffa450edef68>1999-10-05 01:07:56 +0000
commitad4fb154bcceb30c202738ce721a74ce04293b9a (patch)
tree8bab25a61ca5b3cc9b989f3c0915af1c4df69851 /locks/win32
parent69d7693a1181b6418c700f82863b9259711bedca (diff)
downloadlibapr-ad4fb154bcceb30c202738ce721a74ce04293b9a.tar.gz
1. Add Win32 CriticalSections for intra-process locking
2. Another argument swap git-svn-id: http://svn.apache.org/repos/asf/apr/apr/trunk@59264 13f79535-47bb-0310-9956-ffa450edef68
Diffstat (limited to 'locks/win32')
-rw-r--r--locks/win32/locks.c70
-rw-r--r--locks/win32/locks.h3
2 files changed, 53 insertions, 20 deletions
diff --git a/locks/win32/locks.c b/locks/win32/locks.c
index 1ec23521f..08cbd2167 100644
--- a/locks/win32/locks.c
+++ b/locks/win32/locks.c
@@ -68,32 +68,49 @@ ap_status_t ap_create_lock(ap_context_t *cont, ap_locktype_e type,
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_child_init_lock(struct lock_t **lock, ap_context_t *cont, char *f
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;
+ } else {
+ rv = WaitForSingleObject(lock->mutex, INFINITE);
+
+ if (rv == WAIT_OBJECT_0 || rv == WAIT_ABANDONED) {
+ return APR_SUCCESS;
+ }
+ if (rv == WAIT_TIMEOUT) {
+ return APR_TIMEUP;
+ }
}
- 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_destroy_lock(struct lock_t *lock)
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 @@ ap_status_t ap_get_os_lock(struct lock_t *lock, ap_os_lock_t *thelock)
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;
diff --git a/locks/win32/locks.h b/locks/win32/locks.h
index 7ae4f7031..c930efd50 100644
--- a/locks/win32/locks.h
+++ b/locks/win32/locks.h
@@ -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;
};