summaryrefslogtreecommitdiff
path: root/src/global.c
diff options
context:
space:
mode:
authorCarlos Martín Nieto <carlos@cmartin.tk>2012-08-18 22:11:49 +0200
committerCarlos Martín Nieto <cmn@elego.de>2012-08-20 12:02:52 +0200
commit8cef828d8d115c1f98678c13721fee59ca4540b7 (patch)
tree811ff0ad2b4b324cf4b11fd0f2b0ede1fdc04071 /src/global.c
parent1a10fded40875f986164b80c6efd414cd1507cb8 (diff)
downloadlibgit2-8cef828d8d115c1f98678c13721fee59ca4540b7.tar.gz
Make the memory-window conrol structures global
Up to now, the idea was that the user would do all the operations for one repository in the same thread. Thus we could have the memory-mapped window information thread-local and avoid any locking. This is not practical in a few environments, such as Apple's GCD which allocates threads arbitrarily or the .NET CLR, where the OS-level thread can change at any moment. Make the control structure global and protect it with a mutex so we don't depend on the thread currently executing the code.
Diffstat (limited to 'src/global.c')
-rw-r--r--src/global.c5
1 files changed, 5 insertions, 0 deletions
diff --git a/src/global.c b/src/global.c
index 368c6c664..691f0d4f6 100644
--- a/src/global.c
+++ b/src/global.c
@@ -9,6 +9,9 @@
#include "git2/threads.h"
#include "thread-utils.h"
+
+git_mutex git__mwindow_mutex;
+
/**
* Handle the global state with TLS
*
@@ -47,12 +50,14 @@ void git_threads_init(void)
_tls_index = TlsAlloc();
_tls_init = 1;
+ git_mutex_init(&git__mwindow_mutex);
}
void git_threads_shutdown(void)
{
TlsFree(_tls_index);
_tls_init = 0;
+ git_mutex_free(&git__mwindow_mutex);
}
git_global_st *git__global_state(void)