summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorÆvar Arnfjörð Bjarmason <avarab@gmail.com>2017-04-16 22:20:55 +0000
committerJunio C Hamano <gitster@pobox.com>2017-04-16 21:34:03 -0700
commit200eab668f46f763726a38aa83fd34f25965b6f2 (patch)
tree3f4ffe2b4d3276ca57c6faa92bfecea1784eefcd
parent49800c940790cc7465d1b03e08d472ffd8684808 (diff)
downloadgit-200eab668f46f763726a38aa83fd34f25965b6f2.tar.gz
grep: assert that threading is enabled when calling grep_{lock,unlock}
Change the grep_{lock,unlock} functions to assert that num_threads is true, instead of only locking & unlocking the pthread mutex lock when it is. These functions are never called when num_threads isn't true, this logic has gone through multiple iterations since the initial introduction of grep threading in commit 5b594f457a ("Threaded grep", 2010-01-25), but ever since then they'd only be called if num_threads was true, so this check made the code confusing to read. Replace the check with an assertion, so that it's clear to the reader that this code path is never taken unless we're spawning threads. Signed-off-by: Ævar Arnfjörð Bjarmason <avarab@gmail.com> Signed-off-by: Junio C Hamano <gitster@pobox.com>
-rw-r--r--builtin/grep.c8
1 files changed, 4 insertions, 4 deletions
diff --git a/builtin/grep.c b/builtin/grep.c
index 9304c33e75..c5180be4fc 100644
--- a/builtin/grep.c
+++ b/builtin/grep.c
@@ -73,14 +73,14 @@ static pthread_mutex_t grep_mutex;
static inline void grep_lock(void)
{
- if (num_threads)
- pthread_mutex_lock(&grep_mutex);
+ assert(num_threads);
+ pthread_mutex_lock(&grep_mutex);
}
static inline void grep_unlock(void)
{
- if (num_threads)
- pthread_mutex_unlock(&grep_mutex);
+ assert(num_threads);
+ pthread_mutex_unlock(&grep_mutex);
}
/* Signalled when a new work_item is added to todo. */