From 05e924d02bcd46fe530229ea5e4e9d66b2581c49 Mon Sep 17 00:00:00 2001 From: Cliff Woolley Date: Mon, 18 Mar 2002 06:37:32 +0000 Subject: [PATCH] Get mod_mem_cache to compile cleanly again on linux, where apr_atomic_t is a struct. git-svn-id: https://svn.apache.org/repos/asf/httpd/httpd/trunk@93995 13f79535-47bb-0310-9956-ffa450edef68 --- modules/experimental/mod_cache.h | 10 ++++++++++ modules/experimental/mod_mem_cache.c | 24 +++++++++++++++++------- 2 files changed, 27 insertions(+), 7 deletions(-) diff --git a/modules/experimental/mod_cache.h b/modules/experimental/mod_cache.h index 2a8106cf3f..dad453c30b 100644 --- a/modules/experimental/mod_cache.h +++ b/modules/experimental/mod_cache.h @@ -108,6 +108,12 @@ #include #endif +/* USE_ATOMICS should be replaced with the appropriate APR feature macro */ +#define USE_ATOMICS +#ifdef USE_ATOMICS +#include "apr_atomic.h" +#endif + #ifndef MAX #define MAX(a,b) ((a) > (b) ? (a) : (b)) #endif @@ -203,7 +209,11 @@ struct cache_object { void *vobj; /* Opaque portion (specific to the cache implementation) of the cache object */ apr_size_t count; /* Number of body bytes written to the cache so far */ int complete; +#ifdef USE_ATOMICS + apr_atomic_t refcount; +#else apr_size_t refcount; +#endif apr_size_t cleanup; }; diff --git a/modules/experimental/mod_mem_cache.c b/modules/experimental/mod_mem_cache.c index 6b516eac0a..485fc143a2 100644 --- a/modules/experimental/mod_mem_cache.c +++ b/modules/experimental/mod_mem_cache.c @@ -66,12 +66,6 @@ #include #endif -/* USE_ATOMICS should be replaced with the appropriate APR feature macro */ -#define USE_ATOMICS -#ifdef USE_ATOMICS -#include "apr_atomic.h" -#endif - #if !APR_HAS_THREADS #error This module does not currently compile unless you have a thread-capable APR. Sorry! #endif @@ -360,7 +354,11 @@ static int create_entity(cache_handle_t *h, request_rec *r, obj->vobj = mobj; mobj->m_len = len; obj->complete = 0; +#ifdef USE_ATOMICS + apr_atomic_set(&obj->refcount, 1); +#else obj->refcount = 1; +#endif /* Place the cache_object_t into the hash table. * Note: Perhaps we should wait to put the object in the @@ -431,7 +429,11 @@ static int open_entity(cache_handle_t *h, request_rec *r, const char *type, cons APR_HASH_KEY_STRING); if (obj) { if (obj->complete) { +#ifdef USE_ATOMICS + apr_atomic_inc(&obj->refcount); +#else obj->refcount++; +#endif apr_pool_cleanup_register(r->pool, obj, decrement_refcount, apr_pool_cleanup_null); } @@ -595,7 +597,7 @@ static int remove_url(const char *type, const char *key) obj->cleanup = 1; #ifdef USE_ATOMICS /* Refcount increment MUST be made under protection of the lock */ - obj->refcount++; + apr_atomic_inc(&obj->refcount); #else if (!obj->refcount) { cleanup_cache_object(obj); @@ -758,7 +760,11 @@ static apr_status_t write_body(cache_handle_t *h, request_rec *r, apr_bucket_bri apr_os_file_get(&(mobj->fd), tmpfile); obj->cleanup = 0; +#ifdef USE_ATOMICS + (void)apr_atomic_dec(&obj->refcount); +#else obj->refcount--; /* Count should be 0 now */ +#endif apr_pool_cleanup_kill(r->pool, obj, decrement_refcount); /* Open for business */ @@ -788,7 +794,11 @@ static apr_status_t write_body(cache_handle_t *h, request_rec *r, apr_bucket_bri if (APR_BUCKET_IS_EOS(e)) { obj->cleanup = 0; +#ifdef USE_ATOMICS + (void)apr_atomic_dec(&obj->refcount); +#else obj->refcount--; /* Count should be 0 now */ +#endif apr_pool_cleanup_kill(r->pool, obj, decrement_refcount); /* Open for business */ -- 2.40.0