aboutsummaryrefslogtreecommitdiff
path: root/builtin
diff options
context:
space:
mode:
authorJunio C Hamano <gitster@pobox.com>2011-10-27 12:04:02 -0700
committerJunio C Hamano <gitster@pobox.com>2011-10-27 12:04:02 -0700
commit220c0453c12349a8ad4252bcaffbab5a96aeaa31 (patch)
treed20b014198ca3d2bb7184e9e9ada7f7d3b708b9c /builtin
parent82bc9f515c93cdb66f87092c7e270b8de112919f (diff)
parent764161391f2dd3fc12a5bec1385e0ab40dd90fd6 (diff)
downloadgit-220c0453c12349a8ad4252bcaffbab5a96aeaa31.tar.gz
git-220c0453c12349a8ad4252bcaffbab5a96aeaa31.tar.xz
Merge branch 'js/grep-mutex'
* js/grep-mutex: builtin/grep: simplify lock_and_read_sha1_file() builtin/grep: make lock/unlock into static inline functions git grep: be careful to use mutexes only when they are initialized
Diffstat (limited to 'builtin')
-rw-r--r--builtin/grep.c37
1 files changed, 26 insertions, 11 deletions
diff --git a/builtin/grep.c b/builtin/grep.c
index 7d0779f6c..3d7329d78 100644
--- a/builtin/grep.c
+++ b/builtin/grep.c
@@ -74,13 +74,32 @@ static int all_work_added;
/* This lock protects all the variables above. */
static pthread_mutex_t grep_mutex;
+static inline void grep_lock(void)
+{
+ if (use_threads)
+ pthread_mutex_lock(&grep_mutex);
+}
+
+static inline void grep_unlock(void)
+{
+ if (use_threads)
+ pthread_mutex_unlock(&grep_mutex);
+}
+
/* Used to serialize calls to read_sha1_file. */
static pthread_mutex_t read_sha1_mutex;
-#define grep_lock() pthread_mutex_lock(&grep_mutex)
-#define grep_unlock() pthread_mutex_unlock(&grep_mutex)
-#define read_sha1_lock() pthread_mutex_lock(&read_sha1_mutex)
-#define read_sha1_unlock() pthread_mutex_unlock(&read_sha1_mutex)
+static inline void read_sha1_lock(void)
+{
+ if (use_threads)
+ pthread_mutex_lock(&read_sha1_mutex);
+}
+
+static inline void read_sha1_unlock(void)
+{
+ if (use_threads)
+ pthread_mutex_unlock(&read_sha1_mutex);
+}
/* Signalled when a new work_item is added to todo. */
static pthread_cond_t cond_add;
@@ -354,13 +373,9 @@ static void *lock_and_read_sha1_file(const unsigned char *sha1, enum object_type
{
void *data;
- if (use_threads) {
- read_sha1_lock();
- data = read_sha1_file(sha1, type, size);
- read_sha1_unlock();
- } else {
- data = read_sha1_file(sha1, type, size);
- }
+ read_sha1_lock();
+ data = read_sha1_file(sha1, type, size);
+ read_sha1_unlock();
return data;
}