aboutsummaryrefslogtreecommitdiff
path: root/grep.h
diff options
context:
space:
mode:
authorJeff King <peff@peff.net>2012-02-02 03:18:41 -0500
committerJunio C Hamano <gitster@pobox.com>2012-02-02 10:36:07 -0800
commitb3aeb285d0ac1dcb4d578a61a68e08646f96501f (patch)
treef299d6f58379e87987f0029d6bed85b7b9719005 /grep.h
parent78db6ea9dc1a872f9d07a36fe7aec700a5c963b9 (diff)
downloadgit-b3aeb285d0ac1dcb4d578a61a68e08646f96501f.tar.gz
git-b3aeb285d0ac1dcb4d578a61a68e08646f96501f.tar.xz
grep: move sha1-reading mutex into low-level code
The multi-threaded git-grep code needs to serialize access to the thread-unsafe read_sha1_file call. It does this with a mutex that is local to builtin/grep.c. Let's instead push this down into grep.c, where it can be used by both builtin/grep.c and grep.c. This will let us safely teach the low-level grep.c code tricks that involve reading from the object db. Signed-off-by: Jeff King <peff@peff.net> Signed-off-by: Junio C Hamano <gitster@pobox.com>
Diffstat (limited to 'grep.h')
-rw-r--r--grep.h17
1 files changed, 17 insertions, 0 deletions
diff --git a/grep.h b/grep.h
index 3653bb333..4f1b0251b 100644
--- a/grep.h
+++ b/grep.h
@@ -139,6 +139,23 @@ extern int grep_threads_ok(const struct grep_opt *opt);
*/
extern int grep_use_locks;
extern pthread_mutex_t grep_attr_mutex;
+extern pthread_mutex_t grep_read_mutex;
+
+static inline void grep_read_lock(void)
+{
+ if (grep_use_locks)
+ pthread_mutex_lock(&grep_read_mutex);
+}
+
+static inline void grep_read_unlock(void)
+{
+ if (grep_use_locks)
+ pthread_mutex_unlock(&grep_read_mutex);
+}
+
+#else
+#define grep_read_lock()
+#define grep_read_unlock()
#endif
#endif