#include <arpa/inet.h>
#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
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;
};
#include <unistd.h>
#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
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
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);
}
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);
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 */
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 */