Re: [PATCH] fix threaded grep for machines with only one cpu
- From
Junio C Hamano <gitster@pobox.com>
- Date
- Feb 16, 2010, 02:39 UTC
- Message-ID
- <7vljetlx8r.fsf@alter.siamese.dyndns.org>
- In-Reply-To
- <7vocjpnc5v.fsf@alter.siamese.dyndns.org>
Junio C Hamano <gitster@pobox.com> writes:
> Is this the answer to my question?
IOW, please try this patch. I am planning to queue it to 'maint' as part of 1.7.0.1 if this is the right solution (which I obviously think it is).
-- >8 -- From: Junio C Hamano <gitster@pobox.com> Date: Mon, 15 Feb 2010 18:34:28 -0800 Subject: [PATCH] Fix use of mutex in threaded grep
The program can decide at runtime not to use threading even if the support is compiled in. In such a case, mutexes are not necessary and left uninitialized. But the code incorrectly tried to take and release the read_sha1_mutex unconditionally.
Signed-off-by: Junio C Hamano <gitster@pobox.com> --- builtin-grep.c | 4 ++-- 1 files changed, 2 insertions(+), 2 deletions(-)
diff --git a/builtin-grep.c b/builtin-grep.c index 26d4deb..5c1545e 100644 --- a/builtin-grep.c +++ b/builtin-grep.c @@ -81,8 +81,8 @@ 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) +#define read_sha1_lock() do { if (use_threads) pthread_mutex_lock(&read_sha1_mutex); } while (0) +#define read_sha1_unlock() do { if (use_threads) pthread_mutex_unlock(&read_sha1_mutex); } while (0) /* Signalled when a new work_item is added to todo. */ static pthread_cond_t cond_add;
-- 1.7.0.17.g7e5eb