Commit fcd876e0 authored by William A. Rowe Jr's avatar William A. Rowe Jr
Browse files

  Thread saftey lock for mod_rewrite's cache... I'm sure others will have
  some 'better ideas' but this will work for now.

Submitted by: Brian Pane <bpane@pacbell.net>


git-svn-id: https://svn.apache.org/repos/asf/httpd/httpd/trunk@91612 13f79535-47bb-0310-9956-ffa450edef68
parent e301b4c7
Loading
Loading
Loading
Loading
+9 −0
Original line number Diff line number Diff line
Changes with Apache 2.0.27-dev

  *) Introduced thread saftey for mod_rewrite's internal cache.
     [Brian Pane <bpane@pacbell.net>]

  *) Simplified mod_env's directives to behave as most directives are
     expected, in that UnsetEnv will not unset a SetEnv and PassEnv 
     directive following that UnsetEnv within the same container.
     Also provides a runtime startup warning if a PassEnv configured 
     environment value is undefined.  [William Rowe]

  *) The worker MPM is now completely ported to APR's new lock API. It
     uses native APR types for thread mutexes, cross-process mutexes,
     and condition variables.  [Aaron Bannert]
+36 −3
Original line number Diff line number Diff line
@@ -3665,6 +3665,9 @@ static cache *init_cache(apr_pool_t *p)
    if (apr_pool_create(&c->pool, p) != APR_SUCCESS)
		return NULL;
    c->lists = apr_array_make(c->pool, 2, sizeof(cachelist));
#if APR_HAS_THREADS
    (void)apr_lock_create(&(c->lock), APR_MUTEX, APR_INTRAPROCESS, NULL, p);
#endif
    return c;
}

@@ -3755,6 +3758,10 @@ static void store_cache_string(cache *c, const char *res, cacheentry *ce)
    cachetlbentry *t;
    int found_list;

#if APR_HAS_THREADS
    apr_lock_acquire(c->lock);
#endif

    found_list = 0;
    /* first try to edit an existing entry */
    for (i = 0; i < c->lists->nelts; i++) {
@@ -3767,6 +3774,9 @@ static void store_cache_string(cache *c, const char *res, cacheentry *ce)
            if (e != NULL) {
                e->time  = ce->time;
                e->value = apr_pstrdup(c->pool, ce->value);
#if APR_HAS_THREADS
                apr_lock_release(c->lock);
#endif
                return;
            }

@@ -3777,6 +3787,9 @@ static void store_cache_string(cache *c, const char *res, cacheentry *ce)
                    e->value = apr_pstrdup(c->pool, ce->value);
                    cache_tlb_replace((cachetlbentry *)l->tlb->elts,
                                      (cacheentry *)l->entries->elts, e);
#if APR_HAS_THREADS
                    apr_lock_release(c->lock);
#endif
                    return;
                }
            }
@@ -3807,11 +3820,17 @@ static void store_cache_string(cache *c, const char *res, cacheentry *ce)
            e->value = apr_pstrdup(c->pool, ce->value);
            cache_tlb_replace((cachetlbentry *)l->tlb->elts,
                              (cacheentry *)l->entries->elts, e);
#if APR_HAS_THREADS
            apr_lock_release(c->lock);
#endif
            return;
        }
    }

    /* not reached, but when it is no problem... */
#if APR_HAS_THREADS
    apr_lock_release(c->lock);
#endif
    return;
}

@@ -3822,23 +3841,37 @@ static cacheentry *retrieve_cache_string(cache *c, const char *res, char *key)
    cachelist *l;
    cacheentry *e;

#if APR_HAS_THREADS
    apr_lock_acquire(c->lock);
#endif

    for (i = 0; i < c->lists->nelts; i++) {
        l = &(((cachelist *)c->lists->elts)[i]);
        if (strcmp(l->resource, res) == 0) {

            e = cache_tlb_lookup((cachetlbentry *)l->tlb->elts,
                                 (cacheentry *)l->entries->elts, key);
            if (e != NULL)
            if (e != NULL) {
#if APR_HAS_THREADS
                apr_lock_release(c->lock);
#endif
                return e;
            }

            for (j = 0; j < l->entries->nelts; j++) {
                e = &(((cacheentry *)l->entries->elts)[j]);
                if (strcmp(e->key, key) == 0) {
#if APR_HAS_THREADS
                    apr_lock_release(c->lock);
#endif
                    return e;
                }
            }
        }
    }
#if APR_HAS_THREADS
    apr_lock_release(c->lock);
#endif
    return NULL;
}

+6 −0
Original line number Diff line number Diff line
@@ -112,6 +112,9 @@
#include <sys/types.h>
#endif

#if APR_HAS_THREADS
#include "apr_lock.h"
#endif
#include "ap_config.h"

    /* Include from the Apache server ... */
@@ -322,6 +325,9 @@ typedef struct cachelist {
typedef struct cache {
    apr_pool_t         *pool;
    apr_array_header_t *lists;
#if APR_HAS_THREADS
    apr_lock_t *lock;
#endif
} cache;