Welcome to mirror list, hosted at ThFree Co, Russian Federation.

github.com/mono/libgit2.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorRussell Belfer <rb@github.com>2013-04-15 11:09:03 +0400
committerVicent Marti <tanoku@gmail.com>2013-04-22 18:52:07 +0400
commit536078688549ac3d50483eecdec5a8169d921927 (patch)
tree3ceb9965aba3f946b89bbbd99a8071707351d50f /src/pack.c
parent116bbdf0446cd5335b73e691c3352f368eac9b8f (diff)
Further threading fixes
This builds on the earlier thread safety work to make it so that setting the odb, index, refdb, or config for a repository is done in a threadsafe manner with minimized locking time. This is done by adding a lock to the repository object and using it to guard the assignment of the above listed pointers. The lock is only held to assign the pointer value. This also contains some minor fixes to the other work with pack files to reduce the time that locks are being held to and fix an apparently memory leak.
Diffstat (limited to 'src/pack.c')
-rw-r--r--src/pack.c19
1 files changed, 8 insertions, 11 deletions
diff --git a/src/pack.c b/src/pack.c
index 1bffb4778..3a2e7fb5a 100644
--- a/src/pack.c
+++ b/src/pack.c
@@ -299,29 +299,27 @@ static int pack_index_open(struct git_pack_file *p)
int error = 0;
size_t name_len, base_len;
- if ((error = git_mutex_lock(&p->lock)) < 0)
- return error;
-
if (p->index_map.data)
- goto done;
+ return 0;
name_len = strlen(p->pack_name);
assert(name_len > strlen(".pack")); /* checked by git_pack_file alloc */
- if ((idx_name = git__malloc(name_len)) == NULL) {
- error = -1;
- goto done;
- }
+ if ((idx_name = git__malloc(name_len)) == NULL)
+ return -1;
base_len = name_len - strlen(".pack");
memcpy(idx_name, p->pack_name, base_len);
memcpy(idx_name + base_len, ".idx", sizeof(".idx"));
- error = pack_index_check(idx_name, p);
+ if ((error = git_mutex_lock(&p->lock)) < 0)
+ return error;
+
+ if (!p->index_map.data)
+ error = pack_index_check(idx_name, p);
git__free(idx_name);
-done:
git_mutex_unlock(&p->lock);
return error;
@@ -820,7 +818,6 @@ void git_packfile_free(struct git_pack_file *p)
cache_free(&p->bases);
git_mwindow_free_all(&p->mwf);
- git_mwindow_file_deregister(&p->mwf);
if (p->mwf.fd != -1)
p_close(p->mwf.fd);