summaryrefslogtreecommitdiff
path: root/src/thread-utils.h
diff options
context:
space:
mode:
authorRussell Belfer <rb@github.com>2014-03-14 13:20:51 -0700
committerRussell Belfer <rb@github.com>2014-04-17 14:43:45 -0700
commit8a2834d34173220c56bd1898397c0e6d200f327d (patch)
tree62d91bb19bc017a7bb5eb829bf2e52f04581d98c /src/thread-utils.h
parent40ed499039f887ebcb0b5badf0157519148398b8 (diff)
downloadlibgit2-8a2834d34173220c56bd1898397c0e6d200f327d.tar.gz
Index locking and entry allocation changes
This makes the lock management on the index a little bit broader, having a number of routines hold the lock across looking up the item to be modified and actually making the modification. Still not true thread safety, but more pure index modifications are now safe which allows the simple cases (such as starting up a diff while index modifications are underway) safe enough to get the snapshot without hitting allocation problems. As part of this, I simplified the allocation of index entries to use a flex array and just put the path at the end of the index entry. This makes every entry self-contained and makes it a little easier to feel sure that pointers to strings aren't being accidentally copied and freed while other references are still being held.
Diffstat (limited to 'src/thread-utils.h')
-rw-r--r--src/thread-utils.h7
1 files changed, 7 insertions, 0 deletions
diff --git a/src/thread-utils.h b/src/thread-utils.h
index 914c1357d..50d8610a3 100644
--- a/src/thread-utils.h
+++ b/src/thread-utils.h
@@ -47,6 +47,12 @@ typedef git_atomic git_atomic_ssize;
#define git_thread_exit(status) pthread_exit(status)
#define git_thread_join(id, status) pthread_join(id, status)
+#if defined(GIT_WIN32)
+#define git_thread_yield() Sleep(0)
+#else
+#define git_thread_yield() sched_yield()
+#endif
+
/* Pthreads Mutex */
#define git_mutex pthread_mutex_t
#define git_mutex_init(a) pthread_mutex_init(a, NULL)
@@ -176,6 +182,7 @@ GIT_INLINE(int64_t) git_atomic64_add(git_atomic64 *a, int64_t addend)
#define git_thread_kill(thread) (void)0
#define git_thread_exit(status) (void)0
#define git_thread_join(id, status) (void)0
+#define git_thread_yield() (void)0
/* Pthreads Mutex */
#define git_mutex unsigned int