Here's a small cleanup on top the existing patch. I don't believe it fixes any real bugs, but it's Obviously Correct (TM).
I worked on it while resolving issues with the original patch for #692179 commit d9ae7c815e8a98eeb214ea7e8495d95a458761a7 Author: Eric Wong <normalper...@yhbt.net> Date: Thu Nov 8 00:22:08 2012 +0000 filecache: reduce files_mutex contention There's no need to hold the global mutex to update per-file flags, so only update flags after we've released the global mutex.
>From d9ae7c815e8a98eeb214ea7e8495d95a458761a7 Mon Sep 17 00:00:00 2001 From: Eric Wong <normalper...@yhbt.net> Date: Thu, 8 Nov 2012 00:22:08 +0000 Subject: [PATCH 3/3] filecache: reduce files_mutex contention There's no need to hold the global mutex to update per-file flags, so only update flags after we've released the global mutex. --- src/filecache.c | 10 ++++++---- 1 file changed, 6 insertions(+), 4 deletions(-) diff --git a/src/filecache.c b/src/filecache.c index a257a42..8b26b68 100644 --- a/src/filecache.c +++ b/src/filecache.c @@ -185,9 +185,6 @@ void* file_cache_open(const char *path, int flags) { pthread_mutex_lock(&files_mutex); if ((fi = file_cache_get_unlocked(path))) { - pthread_mutex_lock(&fi->mutex); - file_cache_update_flags_unlocked(fi, flags); - pthread_mutex_unlock(&fi->mutex); cached = 1; } else { fi = calloc(1, sizeof(struct file_info)); @@ -202,8 +199,13 @@ void* file_cache_open(const char *path, int flags) { pthread_mutex_unlock(&files_mutex); - if (cached) + if (cached) { + pthread_mutex_lock(&fi->mutex); + file_cache_update_flags_unlocked(fi, flags); + pthread_mutex_unlock(&fi->mutex); + return fi; + } snprintf(tempfile, sizeof(tempfile), "%s/fusedav-cache-XXXXXX", "/tmp"); if ((fi->fd = mkstemp(tempfile)) < 0) -- 1.8.0.3.gdd57fab.dirty