bnicholes 2002/06/11 08:34:26
Modified: file_io/netware filestat.c
Log:
Switch to a Reader/Writer lock to try to avoid lock contention when accessing
the hash table.
Revision Changes Path
1.12 +27 -2 apr/file_io/netware/filestat.c
Index: filestat.c
===================================================================
RCS file: /home/cvs/apr/file_io/netware/filestat.c,v
retrieving revision 1.11
retrieving revision 1.12
diff -u -r1.11 -r1.12
--- filestat.c 31 May 2002 22:17:42 -0000 1.11
+++ filestat.c 11 Jun 2002 15:34:26 -0000 1.12
@@ -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)
{
@@ -226,6 +229,9 @@
#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)
@@ -235,6 +241,9 @@
#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;
struct stat *info;
@@ -259,7 +268,7 @@
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
}
@@ -270,6 +279,10 @@
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);
}
@@ -280,10 +293,16 @@
#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. */
if (stat_entry) {
@@ -304,6 +323,9 @@
#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. */
if (!stat_entry) {
@@ -329,6 +351,9 @@
}
#ifdef USE_CSTAT_MUTEX
apr_thread_mutex_unlock(statcache_mutex);
+#endif
+#ifdef USE_CSTAT_RWLOCK
+ apr_thread_rwlock_unlock(statcache_mutex);
#endif
}
else