summaryrefslogtreecommitdiff
path: root/src/cache.c
diff options
context:
space:
mode:
authorCarlos Martín Nieto <cmn@dwim.me>2014-09-30 04:38:05 +0200
committerCarlos Martín Nieto <cmn@dwim.me>2014-09-30 04:38:05 +0200
commitaf6cc38fc0acba14277ebfd247e0a46a867a2c33 (patch)
treedef8c9608166385421ca769972b93258e1066db8 /src/cache.c
parent3a728fb508ea3eea8033a9e338c61a6421ad21b2 (diff)
parenta2a23322193eeca5d2912c0b74c5374f8ec21737 (diff)
downloadlibgit2-af6cc38fc0acba14277ebfd247e0a46a867a2c33.tar.gz
Merge remote-tracking branch 'upstream/master' into cmn/describe
Diffstat (limited to 'src/cache.c')
-rw-r--r--src/cache.c18
1 files changed, 9 insertions, 9 deletions
diff --git a/src/cache.c b/src/cache.c
index 36ce66570..8dc9cbf9c 100644
--- a/src/cache.c
+++ b/src/cache.c
@@ -68,8 +68,8 @@ int git_cache_init(git_cache *cache)
{
memset(cache, 0, sizeof(*cache));
cache->map = git_oidmap_alloc();
- if (git_mutex_init(&cache->lock)) {
- giterr_set(GITERR_OS, "Failed to initialize cache mutex");
+ if (git_rwlock_init(&cache->lock)) {
+ giterr_set(GITERR_OS, "Failed to initialize cache rwlock");
return -1;
}
return 0;
@@ -94,19 +94,19 @@ static void clear_cache(git_cache *cache)
void git_cache_clear(git_cache *cache)
{
- if (git_mutex_lock(&cache->lock) < 0)
+ if (git_rwlock_wrlock(&cache->lock) < 0)
return;
clear_cache(cache);
- git_mutex_unlock(&cache->lock);
+ git_rwlock_wrunlock(&cache->lock);
}
void git_cache_free(git_cache *cache)
{
git_cache_clear(cache);
git_oidmap_free(cache->map);
- git_mutex_free(&cache->lock);
+ git_rwlock_free(&cache->lock);
git__memzero(cache, sizeof(*cache));
}
@@ -152,7 +152,7 @@ static void *cache_get(git_cache *cache, const git_oid *oid, unsigned int flags)
khiter_t pos;
git_cached_obj *entry = NULL;
- if (!git_cache__enabled || git_mutex_lock(&cache->lock) < 0)
+ if (!git_cache__enabled || git_rwlock_rdlock(&cache->lock) < 0)
return NULL;
pos = kh_get(oid, cache->map, oid);
@@ -166,7 +166,7 @@ static void *cache_get(git_cache *cache, const git_oid *oid, unsigned int flags)
}
}
- git_mutex_unlock(&cache->lock);
+ git_rwlock_rdunlock(&cache->lock);
return entry;
}
@@ -185,7 +185,7 @@ static void *cache_store(git_cache *cache, git_cached_obj *entry)
if (!cache_should_store(entry->type, entry->size))
return entry;
- if (git_mutex_lock(&cache->lock) < 0)
+ if (git_rwlock_wrlock(&cache->lock) < 0)
return entry;
/* soften the load on the cache */
@@ -227,7 +227,7 @@ static void *cache_store(git_cache *cache, git_cached_obj *entry)
}
}
- git_mutex_unlock(&cache->lock);
+ git_rwlock_wrunlock(&cache->lock);
return entry;
}