Skip to content

Commit

Permalink
Switch to a Reader/Writer lock to try to avoid lock contention when a…
Browse files Browse the repository at this point in the history
…ccessing

the hash table.


git-svn-id: https://svn.apache.org/repos/asf/apr/apr/trunk@63491 13f79535-47bb-0310-9956-ffa450edef68
  • Loading branch information
Bradley Nicholes committed Jun 11, 2002
1 parent 5d70191 commit 28dd322
Showing 1 changed file with 27 additions and 2 deletions.
29 changes: 27 additions & 2 deletions file_io/netware/filestat.c
Original file line number Diff line number Diff line change
Expand Up @@ -59,10 +59,13 @@
#include "apr_strings.h"
#include "apr_errno.h"
#include "apr_hash.h"
#define USE_CSTAT_MUTEX
#define USE_CSTAT_RWLOCK
#ifdef USE_CSTAT_MUTEX
#include "apr_thread_mutex.h"
#endif
#ifdef USE_CSTAT_RWLOCK
#include "apr_thread_rwlock.h"
#endif

static apr_filetype_e filetype_from_mode(mode_t mode)
{
Expand Down Expand Up @@ -226,6 +229,9 @@ struct apr_stat_cache_t {
#ifdef USE_CSTAT_MUTEX
apr_thread_mutex_t *statcache_mutex;
#endif
#ifdef USE_CSTAT_RWLOCK
apr_thread_rwlock_t *statcache_mutex;
#endif
};

int cstat (const char *path, struct stat *buf, char **casedName, apr_pool_t *pool)
Expand All @@ -234,6 +240,9 @@ int cstat (const char *path, struct stat *buf, char **casedName, apr_pool_t *poo
apr_hash_t *statCache = NULL;
#ifdef USE_CSTAT_MUTEX
apr_thread_mutex_t *statcache_mutex;
#endif
#ifdef USE_CSTAT_RWLOCK
apr_thread_rwlock_t *statcache_mutex;
#endif
apr_pool_t *gPool = (apr_pool_t *)getGlobalPool();
apr_stat_entry_t *stat_entry;
Expand All @@ -259,7 +268,7 @@ int cstat (const char *path, struct stat *buf, char **casedName, apr_pool_t *poo
with a new mutex lock. */
if (statCacheData) {
statCache = statCacheData->statCache;
#ifdef USE_CSTAT_MUTEX
#if defined(USE_CSTAT_MUTEX) || defined(USE_CSTAT_RWLOCK)
statcache_mutex = statCacheData->statcache_mutex;
#endif
}
Expand All @@ -269,6 +278,10 @@ int cstat (const char *path, struct stat *buf, char **casedName, apr_pool_t *poo
#ifdef USE_CSTAT_MUTEX
apr_thread_mutex_create(&statcache_mutex, APR_THREAD_MUTEX_DEFAULT, gPool);
statCacheData->statcache_mutex = statcache_mutex;
#endif
#ifdef USE_CSTAT_RWLOCK
apr_thread_rwlock_create(&statcache_mutex, gPool);
statCacheData->statcache_mutex = statcache_mutex;
#endif
statCacheData->statCache = statCache;
setStatCache((void*)statCacheData);
Expand All @@ -279,10 +292,16 @@ int cstat (const char *path, struct stat *buf, char **casedName, apr_pool_t *poo
if (statCache) {
#ifdef USE_CSTAT_MUTEX
apr_thread_mutex_lock(statcache_mutex);
#endif
#ifdef USE_CSTAT_RWLOCK
apr_thread_rwlock_rdlock(statcache_mutex);
#endif
stat_entry = (apr_stat_entry_t*) apr_hash_get(statCache, path, APR_HASH_KEY_STRING);
#ifdef USE_CSTAT_MUTEX
apr_thread_mutex_unlock(statcache_mutex);
#endif
#ifdef USE_CSTAT_RWLOCK
apr_thread_rwlock_unlock(statcache_mutex);
#endif
/* If we got an entry then check the expiration time. If the entry
hasn't expired yet then copy the information and return. */
Expand All @@ -303,6 +322,9 @@ int cstat (const char *path, struct stat *buf, char **casedName, apr_pool_t *poo
*casedName = case_filename(pool, path);
#ifdef USE_CSTAT_MUTEX
apr_thread_mutex_lock(statcache_mutex);
#endif
#ifdef USE_CSTAT_RWLOCK
apr_thread_rwlock_wrlock(statcache_mutex);
#endif
/* If we don't have a stat_entry then create one, copy
the data and add it to the hash table. */
Expand All @@ -329,6 +351,9 @@ int cstat (const char *path, struct stat *buf, char **casedName, apr_pool_t *poo
}
#ifdef USE_CSTAT_MUTEX
apr_thread_mutex_unlock(statcache_mutex);
#endif
#ifdef USE_CSTAT_RWLOCK
apr_thread_rwlock_unlock(statcache_mutex);
#endif
}
else
Expand Down

0 comments on commit 28dd322

Please sign in to comment.