{
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;
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));
}
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);
}
}
- git_mutex_unlock(&cache->lock);
+ git_rwlock_rdunlock(&cache->lock);
return 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 */
}
}
- git_mutex_unlock(&cache->lock);
+ git_rwlock_wrunlock(&cache->lock);
return entry;
}