This patch looks right and compiles (without any new warnings), but
after making the changes I realized that I have no idea how to test
this module. Can someone endorse these changes? They simply convert
the old INTRAPROCESS locks to the new apr_thread_mutex_t type in APR.
-aaron
Index: modules/experimental/mod_mem_cache.c
===================================================================
RCS file: /home/cvs/httpd-2.0/modules/experimental/mod_mem_cache.c,v
retrieving revision 1.9
diff -u -r1.9 mod_mem_cache.c
--- modules/experimental/mod_mem_cache.c 2001/09/11 17:41:05 1.9
+++ modules/experimental/mod_mem_cache.c 2001/11/17 20:20:50
@@ -58,8 +58,11 @@
#define CORE_PRIVATE
+#include <apr_thread_mutex.h>
+
#include "mod_cache.h"
#include "ap_mpm.h"
+
#define MAX_CACHE 5000
module AP_MODULE_DECLARE_DATA mem_cache_module;
@@ -94,7 +97,7 @@
} mem_cache_object_t;
typedef struct {
- apr_lock_t *lock;
+ apr_thread_mutex_t *lock;
apr_hash_t *cacheht;
int space;
apr_time_t maxexpire;
@@ -200,7 +203,7 @@
ap_mpm_query(AP_MPMQ_IS_THREADED, &threaded_mpm);
if (threaded_mpm) {
- apr_lock_create(&sconf->lock, APR_MUTEX, APR_INTRAPROCESS, "foo", p);
+ apr_thread_mutex_create(&sconf->lock, APR_THREAD_MUTEX_DEFAULT, p);
}
sconf->cacheht = apr_hash_make(p);
apr_pool_cleanup_register(p, NULL, cleanup_cache_mem, apr_pool_cleanup_null);
@@ -260,14 +263,14 @@
* views of the same content) under a single search key
*/
if (sconf->lock) {
- apr_lock_acquire(sconf->lock);
+ apr_thread_mutex_lock(sconf->lock);
}
tmp_obj = (cache_object_t *) apr_hash_get(sconf->cacheht, key,
APR_HASH_KEY_STRING);
if (!tmp_obj) {
apr_hash_set(sconf->cacheht, obj->key, strlen(obj->key), obj);
}
if (sconf->lock) {
- apr_lock_release(sconf->lock);
+ apr_thread_mutex_unlock(sconf->lock);
}
if (tmp_obj) {
@@ -298,11 +301,11 @@
return DECLINED;
}
if (sconf->lock) {
- apr_lock_acquire(sconf->lock);
+ apr_thread_mutex_lock(sconf->lock);
}
obj = (cache_object_t *) apr_hash_get(sconf->cacheht, key, APR_HASH_KEY_STRING);
if (sconf->lock) {
- apr_lock_release(sconf->lock);
+ apr_thread_mutex_unlock(sconf->lock);
}
if (!obj || !(obj->complete)) {
@@ -324,11 +327,11 @@
cache_object_t *obj = h->cache_obj;
if (sconf->lock) {
- apr_lock_acquire(sconf->lock);
+ apr_thread_mutex_lock(sconf->lock);
}
apr_hash_set(sconf->cacheht, obj->key, strlen(obj->key), NULL);
if (sconf->lock) {
- apr_lock_release(sconf->lock);
+ apr_thread_mutex_unlock(sconf->lock);
}
cleanup_cache_object(obj);
@@ -353,11 +356,11 @@
/* First, find the object in the cache */
if (sconf->lock) {
- apr_lock_acquire(sconf->lock);
+ apr_thread_mutex_lock(sconf->lock);
}
obj = (cache_object_t *) apr_hash_get(sconf->cacheht, key, APR_HASH_KEY_STRING);
if (sconf->lock) {
- apr_lock_release(sconf->lock);
+ apr_thread_mutex_unlock(sconf->lock);
}
if (!obj) {
@@ -366,11 +369,11 @@
/* Found it. Now take it out of the cache and free it. */
if (sconf->lock) {
- apr_lock_acquire(sconf->lock);
+ apr_thread_mutex_lock(sconf->lock);
}
apr_hash_set(sconf->cacheht, obj->key, strlen(obj->key), NULL);
if (sconf->lock) {
- apr_lock_release(sconf->lock);
+ apr_thread_mutex_unlock(sconf->lock);
}
cleanup_cache_object(obj);
@@ -523,8 +526,9 @@
{
int val;
- if (sscanf(arg, "%d", &val) != 1)
- return "CacheSize value must be an integer (kBytes)";
+ if (sscanf(arg, "%d", &val) != 1) {
+ return "CacheSize value must be an integer (kBytes)";
+ }
sconf->space = val;
return NULL;
}