summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authordreid <dreid@13f79535-47bb-0310-9956-ffa450edef68>2001-06-05 08:15:37 +0000
committerdreid <dreid@13f79535-47bb-0310-9956-ffa450edef68>2001-06-05 08:15:37 +0000
commit51a551acabdd690d61b32a140eb35c1fa21df005 (patch)
treebd5d646a7be4fa86989e31aba06d7880d7278acc
parent617d7f11c673551685b5fef657acca30797835f9 (diff)
downloadlibapr-51a551acabdd690d61b32a140eb35c1fa21df005.tar.gz
OK, this basically adds a function that allows us to create
apr_lock_t's using an apr_sms_t for the memory. It's a very small first step, and at present is only intended to be used internally in APR, hence the position of the function definitions in the locks.h file. Given that we don't want to duplicate code where we don't have to, I've added some macros that allow us to do memory allocations regardless of whether we have a pool or sms. This also highlighted that we haven't yet managed to change our member names from cntxt to pool everywhere! The surprise comes in just how far reaching the apr_pool_t goes. As apr_lock.h uses ap_sms_t and apr_sms.h uses apr_lock_t I've moved the tyepdef's into apr.h.in, but this may be bogus... Hopefully this will allow us to get locking into sms and so start moving forward again, and at the same time it starts to throw up the problems for changing our memory system throughout APR. git-svn-id: http://svn.apache.org/repos/asf/apr/apr/trunk@61698 13f79535-47bb-0310-9956-ffa450edef68
-rw-r--r--acconfig.h42
-rw-r--r--include/apr.h.in2
-rw-r--r--include/apr_lock.h3
-rw-r--r--include/apr_sms.h3
-rw-r--r--include/arch/beos/locks.h5
-rw-r--r--include/arch/os2/locks.h6
-rw-r--r--include/arch/unix/locks.h6
-rw-r--r--include/arch/win32/locks.h6
-rw-r--r--locks/unix/crossproc.c21
-rw-r--r--locks/unix/locks.c61
-rw-r--r--locks/win32/locks.c39
11 files changed, 164 insertions, 30 deletions
diff --git a/acconfig.h b/acconfig.h
index b238713b5..35aa1f9b6 100644
--- a/acconfig.h
+++ b/acconfig.h
@@ -67,4 +67,46 @@
#define apr_sigwait(a,b) sigwait((a),(b))
#endif
+/* Macros to deal with using either a pool or an sms
+ * to do memory stuff...
+ */
+#define APR_REGISTER_CLEANUP(struct, data, func, scope) \
+ if (struct->cntxt) { \
+ apr_pool_cleanup_register(struct->cntxt, data, func, scope); \
+ } else { \
+ apr_sms_cleanup_register(struct->mem_sys, APR_CHILD_CLEANUP, \
+ data, func); \
+ }
+
+#define APR_REMOVE_CLEANUP(struct, data, func) \
+ if (struct->cntxt) { \
+ apr_pool_cleanup_kill(struct->cntxt, data, func); \
+ } else { \
+ apr_sms_cleanup_unregister(struct->mem_sys, APR_CHILD_CLEANUP, \
+ data, func); \
+ }
+
+#define APR_MEM_PSTRDUP(struct, ptr, str) \
+ if (struct->cntxt) { \
+ ptr = apr_pstrdup(struct->cntxt, str); \
+ } else { \
+ size_t len = strlen(str) + 1; \
+ ptr = (char*) apr_sms_calloc(struct->mem_sys, len); \
+ memcpy(ptr, str, len); \
+ }
+
+#define APR_MEM_MALLOC(ptr, struct, type) \
+ if (struct->cntxt) { \
+ ptr = (type *)apr_palloc(struct->cntxt, sizeof(type)); \
+ } else { \
+ ptr = (type *)apr_sms_malloc(struct->mem_sys, sizeof(type)); \
+ }
+
+#define APR_MEM_CALLOC(ptr, struct, type) \
+ if (struct->cntxt) { \
+ ptr = (type *)apr_pcalloc(struct->cntxt, sizeof(type)); \
+ } else { \
+ ptr = (type *)apr_sms_calloc(struct->mem_sys, sizeof(type)); \
+ }
+
#endif /* APR_PRIVATE_H */
diff --git a/include/apr.h.in b/include/apr.h.in
index 63136726c..c72981e43 100644
--- a/include/apr.h.in
+++ b/include/apr.h.in
@@ -174,6 +174,8 @@ typedef @ssize_t_value@ apr_ssize_t;
typedef @off_t_value@ apr_off_t;
typedef @socklen_t_value@ apr_socklen_t;
+typedef struct apr_lock_t apr_lock_t;
+typedef struct apr_sms_t apr_sms_t;
/* Mechanisms to properly type numeric literals */
@int64_literal@
diff --git a/include/apr_lock.h b/include/apr_lock.h
index 1be21ed1a..9c5e08fdf 100644
--- a/include/apr_lock.h
+++ b/include/apr_lock.h
@@ -58,6 +58,7 @@
#include "apr.h"
#include "apr_pools.h"
#include "apr_errno.h"
+#include "apr_sms.h"
#ifdef __cplusplus
extern "C" {
@@ -73,8 +74,6 @@ typedef enum {APR_MUTEX, APR_READWRITE} apr_locktype_e;
typedef enum {APR_READER, APR_WRITER} apr_readerwriter_e;
-typedef struct apr_lock_t apr_lock_t;
-
/* Function definitions */
/**
diff --git a/include/apr_sms.h b/include/apr_sms.h
index ec7825ef8..38ff3b88b 100644
--- a/include/apr_sms.h
+++ b/include/apr_sms.h
@@ -79,8 +79,6 @@ extern "C" {
* @package APR memory system
*/
-typedef struct apr_sms_t apr_sms_t;
-
struct apr_sms_cleanup;
/**
@@ -94,6 +92,7 @@ struct apr_sms_t
apr_sms_t **ref_mem_sys;
apr_sms_t *accounting_mem_sys;
const char *identity; /* a string identifying the module */
+ apr_lock_t *lock;
struct apr_sms_cleanup *cleanups;
diff --git a/include/arch/beos/locks.h b/include/arch/beos/locks.h
index ec3e77538..ce9fa6cfa 100644
--- a/include/arch/beos/locks.h
+++ b/include/arch/beos/locks.h
@@ -60,9 +60,11 @@
#include "apr_file_io.h"
#include "apr_general.h"
#include "apr_lib.h"
+#include "apr_sms.h"
struct apr_lock_t {
apr_pool_t *cntxt;
+ apr_sms_t *mem_sys;
apr_locktype_e type;
apr_lockscope_e scope;
/* Inter proc */
@@ -86,6 +88,9 @@ apr_status_t destroy_inter_lock(struct apr_lock_t *lock);
apr_status_t child_init_lock(struct apr_lock_t **lock, apr_pool_t *cont,
const char *fname);
+apr_status_t apr_lock_sms_create(apr_lock_t **lock, apr_locktype_e type,
+ apr_lockscope_e scope, const_char *fname,
+ apr_sms_t *mem_sys);
#endif /* LOCKS_H */
diff --git a/include/arch/os2/locks.h b/include/arch/os2/locks.h
index 7c0a87825..d3edf99d8 100644
--- a/include/arch/os2/locks.h
+++ b/include/arch/os2/locks.h
@@ -57,9 +57,11 @@
#include "apr_lock.h"
#include "apr_file_io.h"
+#include "apr_sms.h"
struct apr_lock_t {
apr_pool_t *cntxt;
+ apr_sms_t *mem_sys;
apr_locktype_e type;
apr_lockscope_e scope;
char *fname;
@@ -69,5 +71,9 @@ struct apr_lock_t {
TIB *tib;
};
+apr_status_t apr_lock_sms_create(apr_lock_t **lock, apr_locktype_e type,
+ apr_lockscope_e scope, const char *fname,
+ apr_sms_t *mem_sys);
+
#endif /* LOCKS_H */
diff --git a/include/arch/unix/locks.h b/include/arch/unix/locks.h
index beaecac25..e34dcc769 100644
--- a/include/arch/unix/locks.h
+++ b/include/arch/unix/locks.h
@@ -60,6 +60,7 @@
#include "apr_general.h"
#include "apr_lib.h"
#include "apr_lock.h"
+#include "apr_sms.h"
/* System headers required by Locks library */
#if APR_HAVE_SYS_TYPES_H
@@ -109,6 +110,7 @@ union semun {
struct apr_lock_t {
apr_pool_t *cntxt;
+ apr_sms_t *mem_sys;
apr_locktype_e type;
apr_lockscope_e scope;
int curr_locked;
@@ -155,5 +157,9 @@ apr_status_t apr_unix_destroy_inter_lock(struct apr_lock_t *lock);
apr_status_t apr_unix_child_init_lock(struct apr_lock_t **lock,
apr_pool_t *cont, const char *fname);
+apr_status_t apr_lock_sms_create(apr_lock_t **lock, apr_locktype_e type,
+ apr_lockscope_e scope, const char *fname,
+ apr_sms_t *mem_sys);
+
#endif /* LOCKS_H */
diff --git a/include/arch/win32/locks.h b/include/arch/win32/locks.h
index 38f8f105a..1083e685e 100644
--- a/include/arch/win32/locks.h
+++ b/include/arch/win32/locks.h
@@ -56,9 +56,11 @@
#define LOCKS_H
#include "apr_lock.h"
+#include "apr_sms.h"
struct apr_lock_t {
apr_pool_t *cntxt;
+ apr_sms_t *mem_sys;
apr_locktype_e type;
apr_lockscope_e scope;
HANDLE mutex;
@@ -66,5 +68,9 @@ struct apr_lock_t {
char *fname;
};
+apr_status_t apr_lock_sms_create(apr_lock_t **lock, apr_locktype_e type,
+ apr_lockscope_e scope, const char *fname,
+ apr_sms_t *mem_sys);
+
#endif /* LOCKS_H */
diff --git a/locks/unix/crossproc.c b/locks/unix/crossproc.c
index ae5b47e30..29df0c174 100644
--- a/locks/unix/crossproc.c
+++ b/locks/unix/crossproc.c
@@ -100,7 +100,7 @@ apr_status_t apr_unix_create_inter_lock(apr_lock_t *new)
return errno;
}
new->curr_locked = 0;
- apr_pool_cleanup_register(new->cntxt, (void *)new, lock_cleanup, apr_pool_cleanup_null);
+ APR_REGISTER_CLEANUP(new, (void *)new, lock_cleanup, apr_pool_cleanup_null);
return APR_SUCCESS;
}
@@ -137,7 +137,7 @@ apr_status_t apr_unix_destroy_inter_lock(apr_lock_t *lock)
apr_status_t stat;
if ((stat = lock_cleanup(lock)) == APR_SUCCESS) {
- apr_pool_cleanup_kill(lock->cntxt, lock, lock_cleanup);
+ APR_REMOVE_CLEANUP(lock, lock, lock_cleanup);
return APR_SUCCESS;
}
return stat;
@@ -223,7 +223,7 @@ apr_status_t apr_unix_create_inter_lock(apr_lock_t *new)
}
new->curr_locked = 0;
- apr_pool_cleanup_register(new->cntxt, (void *)new, lock_cleanup, apr_pool_cleanup_null);
+ APR_REGISTER_CLEANUP(new, (void *)new, lock_cleanup, apr_pool_cleanup_null);
return APR_SUCCESS;
}
@@ -259,7 +259,7 @@ apr_status_t apr_unix_destroy_inter_lock(apr_lock_t *lock)
{
apr_status_t stat;
if ((stat = lock_cleanup(lock)) == APR_SUCCESS) {
- apr_pool_cleanup_kill(lock->cntxt, lock, lock_cleanup);
+ APR_REMOVE_CLEANUP(lock, lock, lock_cleanup);
return APR_SUCCESS;
}
return stat;
@@ -305,7 +305,7 @@ apr_status_t apr_unix_create_inter_lock(apr_lock_t *new)
new->interproc = open(new->fname, O_CREAT | O_WRONLY | O_EXCL, 0644);
}
else {
- new->fname = apr_pstrdup(new->cntxt, "/tmp/aprXXXXXX");
+ APR_MEM_PSTRDUP(new, new->fname, "/tmp/aprXXXXXX")
new->interproc = apr_mkstemp(new->fname);
}
@@ -316,7 +316,7 @@ apr_status_t apr_unix_create_inter_lock(apr_lock_t *new)
new->curr_locked=0;
unlink(new->fname);
- apr_pool_cleanup_register(new->cntxt, new, lock_cleanup, apr_pool_cleanup_null);
+ APR_REGISTER_CLEANUP(new, new, lock_cleanup, apr_pool_cleanup_null);
return APR_SUCCESS;
}
@@ -352,7 +352,7 @@ apr_status_t apr_unix_destroy_inter_lock(apr_lock_t *lock)
{
apr_status_t stat;
if ((stat = lock_cleanup(lock)) == APR_SUCCESS) {
- apr_pool_cleanup_kill(lock->cntxt, lock, lock_cleanup);
+ APR_REMOVE_CLEANUP(lock, lock, lock_cleanup);
return APR_SUCCESS;
}
return stat;
@@ -364,6 +364,7 @@ apr_status_t apr_unix_child_init_lock(apr_lock_t **lock, apr_pool_t *cont,
return APR_SUCCESS;
}
+
#elif (APR_USE_FLOCK_SERIALIZE)
void apr_unix_setup_lock(void)
@@ -387,7 +388,7 @@ apr_status_t apr_unix_create_inter_lock(apr_lock_t *new)
new->interproc = open(new->fname, O_CREAT | O_WRONLY | O_EXCL, 0600);
}
else {
- new->fname = apr_pstrdup(new->cntxt, "/tmp/aprXXXXXX");
+ APR_MEM_PSTRDUP(new, new->fname, "/tmp/aprXXXXXX")
new->interproc = apr_mkstemp(new->fname);
}
@@ -396,7 +397,7 @@ apr_status_t apr_unix_create_inter_lock(apr_lock_t *new)
return errno;
}
new->curr_locked = 0;
- apr_pool_cleanup_register(new->cntxt, (void *)new, lock_cleanup, apr_pool_cleanup_null);
+ APR_REGISTER_CLEANUP(new, (void *)new, lock_cleanup, apr_pool_cleanup_null);
return APR_SUCCESS;
}
@@ -432,7 +433,7 @@ apr_status_t apr_unix_destroy_inter_lock(apr_lock_t *lock)
{
apr_status_t stat;
if ((stat = lock_cleanup(lock)) == APR_SUCCESS) {
- apr_pool_cleanup_kill(lock->cntxt, lock, lock_cleanup);
+ APR_REMOVE_CLEANUP(lock, lock, lock_cleanup);
return APR_SUCCESS;
}
return stat;
diff --git a/locks/unix/locks.c b/locks/unix/locks.c
index f05681b3c..44bbd20ce 100644
--- a/locks/unix/locks.c
+++ b/locks/unix/locks.c
@@ -56,46 +56,38 @@
#include "apr_strings.h"
#include "apr_portable.h"
-apr_status_t apr_lock_create(apr_lock_t **lock, apr_locktype_e type,
- apr_lockscope_e scope, const char *fname,
- apr_pool_t *cont)
+static apr_status_t create_lock(apr_lock_t *new, const char *fname)
{
- apr_lock_t *new;
apr_status_t stat;
- new = (apr_lock_t *)apr_pcalloc(cont, sizeof(apr_lock_t));
-
- new->cntxt = cont;
- new->type = type;
- new->scope = scope;
switch (new->type)
{
case APR_MUTEX:
#if (APR_USE_FCNTL_SERIALIZE) || (APR_USE_FLOCK_SERIALIZE)
/* file-based serialization primitives */
- if (scope != APR_INTRAPROCESS) {
+ if (new->scope != APR_INTRAPROCESS) {
if (fname != NULL) {
- new->fname = apr_pstrdup(cont, fname);
+ APR_MEM_PSTRDUP(new, new->fname, fname);
}
}
#endif
#if APR_PROCESS_LOCK_IS_GLOBAL /* don't need intra lock for APR_LOCKALL */
- if (scope == APR_INTRAPROCESS) {
+ if (new->scope == APR_INTRAPROCESS) {
#else
- if (scope != APR_CROSS_PROCESS) {
+ if (new->scope != APR_CROSS_PROCESS) {
#endif
#if APR_HAS_THREADS
if ((stat = apr_unix_create_intra_lock(new)) != APR_SUCCESS) {
return stat;
}
#else
- if (scope != APR_LOCKALL) {
+ if (new->scope != APR_LOCKALL) {
return APR_ENOTIMPL;
}
#endif
}
- if (scope != APR_INTRAPROCESS) {
+ if (new->scope != APR_INTRAPROCESS) {
if ((stat = apr_unix_create_inter_lock(new)) != APR_SUCCESS) {
return stat;
}
@@ -103,7 +95,7 @@ apr_status_t apr_lock_create(apr_lock_t **lock, apr_locktype_e type,
break;
case APR_READWRITE:
#ifdef HAVE_PTHREAD_RWLOCK_INIT
- if (scope != APR_INTRAPROCESS)
+ if (new->scope != APR_INTRAPROCESS)
return APR_ENOTIMPL;
pthread_rwlock_init(&new->rwlock, NULL);
break;
@@ -111,6 +103,43 @@ apr_status_t apr_lock_create(apr_lock_t **lock, apr_locktype_e type,
return APR_ENOTIMPL;
#endif
}
+ return APR_SUCCESS;
+}
+
+apr_status_t apr_lock_create(apr_lock_t **lock, apr_locktype_e type,
+ apr_lockscope_e scope, const char *fname,
+ apr_pool_t *cont)
+{
+ apr_lock_t *new;
+ apr_status_t stat;
+
+ new = (apr_lock_t *)apr_pcalloc(cont, sizeof(apr_lock_t));
+
+ new->cntxt = cont;
+ new->type = type;
+ new->scope = scope;
+ if ((stat = create_lock(new, fname)) != APR_SUCCESS)
+ return APR_SUCCESS;
+
+ *lock = new;
+ return APR_SUCCESS;
+}
+
+apr_status_t apr_lock_sms_create(apr_lock_t **lock, apr_locktype_e type,
+ apr_lockscope_e scope, const char *fname,
+ apr_sms_t *mem_sys)
+{
+ apr_lock_t *new;
+ apr_status_t stat;
+
+ new = (apr_lock_t *)apr_sms_calloc(mem_sys, sizeof(apr_lock_t));
+
+ new->mem_sys = mem_sys;
+ new->cntxt = NULL;
+ new->type = type;
+ new->scope = scope;
+ if ((stat = create_lock(new, fname)) != APR_SUCCESS)
+ return stat;
*lock = new;
return APR_SUCCESS;
diff --git a/locks/win32/locks.c b/locks/win32/locks.c
index 267b8ad90..b30755dca 100644
--- a/locks/win32/locks.c
+++ b/locks/win32/locks.c
@@ -98,6 +98,45 @@ APR_DECLARE(apr_status_t) apr_lock_create(apr_lock_t **lock,
return APR_SUCCESS;
}
+APR_DECLARE(apr_status_t) apr_lock_sms_create(apr_lock_t **lock,
+ apr_locktype_e type,
+ apr_lockscope_e scope,
+ const char *fname,
+ apr_sms_t *mem_sys)
+{
+ apr_lock_t *newlock;
+ SECURITY_ATTRIBUTES sec;
+
+ if (type == APR_READWRITE)
+ return APR_ENOTIMPL;
+
+ newlock = (apr_lock_t *)apr_sms_malloc(mem_sys, sizeof(apr_lock_t));
+
+ newlock->cntxt = NULL;
+ newlock->mem_sys = mem_sys;
+
+ APR_MEM_PSTRDUP(newlock, newlock->fname, fname);
+ newlock->type = type;
+ newlock->scope = scope;
+ sec.nLength = sizeof(SECURITY_ATTRIBUTES);
+ sec.lpSecurityDescriptor = NULL;
+
+ if (scope == APR_CROSS_PROCESS || scope == APR_LOCKALL) {
+ sec.bInheritHandle = TRUE;
+ }
+ else {
+ sec.bInheritHandle = FALSE;
+ }
+
+ if (scope == APR_INTRAPROCESS) {
+ InitializeCriticalSection(&newlock->section);
+ } else {
+ newlock->mutex = CreateMutex(&sec, FALSE, fname);
+ }
+ *lock = newlock;
+ return APR_SUCCESS;
+}
+
APR_DECLARE(apr_status_t) apr_lock_child_init(apr_lock_t **lock,
const char *fname,
apr_pool_t *cont)