vendor/libgit2/src/cache.c in rugged-0.21.4 vs vendor/libgit2/src/cache.c in rugged-0.22.0b1

- old
+ new

@@ -66,12 +66,12 @@ 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; } @@ -92,23 +92,23 @@ cache->used_memory = 0; } 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)); } /* Called with lock */ static void cache_evict_entries(git_cache *cache) @@ -150,11 +150,11 @@ 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); if (pos != kh_end(cache->map)) { entry = kh_val(cache->map, pos); @@ -164,11 +164,11 @@ } else { git_cached_obj_incref(entry); } } - git_mutex_unlock(&cache->lock); + git_rwlock_rdunlock(&cache->lock); return entry; } static void *cache_store(git_cache *cache, git_cached_obj *entry) @@ -183,11 +183,11 @@ } 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 */ if (git_cache__current_storage.val > git_cache__max_storage) cache_evict_entries(cache); @@ -225,10 +225,10 @@ } else { /* NO OP */ } } - git_mutex_unlock(&cache->lock); + git_rwlock_wrunlock(&cache->lock); return entry; } void *git_cache_store_raw(git_cache *cache, git_odb_object *entry) {