grep: enable threading with -p and -W using lazy attribute lookup

Lazily load the userdiff attributes in match_funcname().  Use a
separate mutex around this loading to protect the (not thread-safe)
attributes machinery.  This lets us re-enable threading with -p and
-W while reducing the overhead caused by looking up attributes.

Signed-off-by: Thomas Rast <trast@student.ethz.ch>
Signed-off-by: Junio C Hamano <gitster@pobox.com>
This commit is contained in:
Thomas Rast
2011-12-12 22:16:07 +01:00
committed by Junio C Hamano
parent b8ffedca6f
commit 0579f91dd7
3 changed files with 63 additions and 33 deletions

10
grep.h
View File

@ -8,6 +8,7 @@ typedef int pcre;
typedef int pcre_extra;
#endif
#include "kwset.h"
#include "thread-utils.h"
enum grep_pat_token {
GREP_PATTERN,
@ -115,6 +116,7 @@ struct grep_opt {
int show_hunk_mark;
int file_break;
int heading;
int use_threads;
void *priv;
void (*output)(struct grep_opt *opt, const void *data, size_t size);
@ -131,4 +133,12 @@ extern int grep_buffer(struct grep_opt *opt, const char *name, char *buf, unsign
extern struct grep_opt *grep_opt_dup(const struct grep_opt *opt);
extern int grep_threads_ok(const struct grep_opt *opt);
#ifndef NO_PTHREADS
/*
* Mutex used around access to the attributes machinery if
* opt->use_threads. Must be initialized/destroyed by callers!
*/
extern pthread_mutex_t grep_attr_mutex;
#endif
#endif