builtin/grep: make lock/unlock into static inline functions

Signed-off-by: Junio C Hamano <gitster@pobox.com>

Junio C Hamano committed Oct 26, 2011 at 11:45 UTC 1487a12ba228c6003f503366f40840eee9887179
1 file changed +23 -5
builtin/grep.c
+23 -5
@@ -74,14 +74,32 @@ static int all_work_added;
74 /* This lock protects all the variables above. */
75 static pthread_mutex_t grep_mutex;
76
77 +static inline void grep_lock(void)
78 +{
79 + if (use_threads)
80 + pthread_mutex_lock(&grep_mutex);
81 +}
82 +
83 +static inline void grep_unlock(void)
84 +{
85 + if (use_threads)
86 + pthread_mutex_unlock(&grep_mutex);
87 +}
88 +
89 /* Used to serialize calls to read_sha1_file. */
90 static pthread_mutex_t read_sha1_mutex;
91
80 -#define WHEN_THREADED(x) do { if (use_threads) (x); } while (0)
81 -#define grep_lock() WHEN_THREADED(pthread_mutex_lock(&grep_mutex))
82 -#define grep_unlock() WHEN_THREADED(pthread_mutex_unlock(&grep_mutex))
83 -#define read_sha1_lock() WHEN_THREADED(pthread_mutex_lock(&read_sha1_mutex))
84 -#define read_sha1_unlock() WHEN_THREADED(pthread_mutex_unlock(&read_sha1_mutex))
92 +static inline void read_sha1_lock(void)
93 +{
94 + if (use_threads)
95 + pthread_mutex_lock(&read_sha1_mutex);
96 +}
97 +
98 +static inline void read_sha1_unlock(void)
99 +{
100 + if (use_threads)
101 + pthread_mutex_unlock(&read_sha1_mutex);
102 +}
103
104 /* Signalled when a new work_item is added to todo. */
105 static pthread_cond_t cond_add;