Skip to content

Commit 8df4c29

Browse files
avargitster
authored andcommitted
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 5b594f4 ("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 <[email protected]> Signed-off-by: Junio C Hamano <[email protected]>
1 parent d1edee4 commit 8df4c29

File tree

1 file changed

+4
-4
lines changed

1 file changed

+4
-4
lines changed

builtin/grep.c

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -73,14 +73,14 @@ static pthread_mutex_t grep_mutex;
7373

7474
static inline void grep_lock(void)
7575
{
76-
if (num_threads)
77-
pthread_mutex_lock(&grep_mutex);
76+
assert(num_threads);
77+
pthread_mutex_lock(&grep_mutex);
7878
}
7979

8080
static inline void grep_unlock(void)
8181
{
82-
if (num_threads)
83-
pthread_mutex_unlock(&grep_mutex);
82+
assert(num_threads);
83+
pthread_mutex_unlock(&grep_mutex);
8484
}
8585

8686
/* Signalled when a new work_item is added to todo. */

0 commit comments

Comments
 (0)