Skip to content

Commit 1487a12

Browse files
committed
builtin/grep: make lock/unlock into static inline functions
Signed-off-by: Junio C Hamano <[email protected]>
1 parent cdf0553 commit 1487a12

File tree

1 file changed

+23
-5
lines changed

1 file changed

+23
-5
lines changed

builtin/grep.c

Lines changed: 23 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -74,14 +74,32 @@ static int all_work_added;
7474
/* This lock protects all the variables above. */
7575
static pthread_mutex_t grep_mutex;
7676

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+
7789
/* Used to serialize calls to read_sha1_file. */
7890
static pthread_mutex_t read_sha1_mutex;
7991

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+
}
85103

86104
/* Signalled when a new work_item is added to todo. */
87105
static pthread_cond_t cond_add;

0 commit comments

Comments
 (0)