summaryrefslogtreecommitdiff
path: root/src/indexer.c
diff options
context:
space:
mode:
authorCarlos Martín Nieto <cmn@dwim.me>2014-06-18 17:13:12 +0200
committerCarlos Martín Nieto <cmn@dwim.me>2014-06-23 21:50:36 +0200
commitb3b66c57930358467395fc3a5bca87edefd25cf4 (patch)
tree1ca1c8fd8bf8fd69156c566a83ac12375b427a5e /src/indexer.c
parent1589aa0c4d48fb130d8a5db28c45cd3d173cde6d (diff)
downloadlibgit2-cmn/global-mwf.tar.gz
Share packs across repository instancescmn/global-mwf
Opening the same repository multiple times will currently open the same file multiple times, as well as map the same region of the file multiple times. This is not necessary, as the packfile data is immutable. Instead of opening and closing packfiles directly, introduce an indirection and allocate packfiles globally. This does mean locking on each packfile open, but we already use this lock for the global mwindow list so it doesn't introduce a new contention point.
Diffstat (limited to 'src/indexer.c')
-rw-r--r--src/indexer.c9
1 files changed, 8 insertions, 1 deletions
diff --git a/src/indexer.c b/src/indexer.c
index 25c3d0537..eb8b23e92 100644
--- a/src/indexer.c
+++ b/src/indexer.c
@@ -18,6 +18,8 @@
#include "oidmap.h"
#include "zstream.h"
+extern git_mutex git__mwindow_mutex;
+
#define UINT31_MAX (0x7FFFFFFF)
struct entry {
@@ -1044,6 +1046,11 @@ void git_indexer_free(git_indexer *idx)
}
git_vector_free_deep(&idx->deltas);
- git_packfile_free(idx->pack);
+
+ if (!git_mutex_lock(&git__mwindow_mutex)) {
+ git_packfile_free(idx->pack);
+ git_mutex_unlock(&git__mwindow_mutex);
+ }
+
git__free(idx);
}