Re: [PATCH 27/36] attr: convert to new threadsafe API
- From
Johannes Schindelin <johannes.schindelin@gmx.de>
- Date
- Oct 26, 2016, 08:52 UTC
- Message-ID
- <alpine.DEB.2.20.1610261049470.3264@virtualbox>
- In-Reply-To
- <20161022233225.8883-28-sbeller@google.com>
Hi Stefan,
On Sat, 22 Oct 2016, Stefan Beller wrote:
Show 9 quoted lines
> @@ -46,6 +47,19 @@ struct git_attr {
> static int attr_nr;
> static struct git_attr *(git_attr_hash[HASHSIZE]);
>
> +#ifndef NO_PTHREADS
> +
> +static pthread_mutex_t attr_mutex;
> +#define attr_lock() pthread_mutex_lock(&attr_mutex)
> +#define attr_unlock() pthread_mutex_unlock(&attr_mutex)This mutex is never initialized. That may work on the system you tested, but it is incorrect, and it does segfault on Windows. A lot.
I need *at least* something like this to make it stop crashing all over the test suite:
-- snipsnap --
diff --git a/attr.c b/attr.c index d5a6aa9..6933504 100644 --- a/attr.c +++ b/attr.c @@ -50,7 +50,16 @@ static struct git_attr *(git_attr_hash[HASHSIZE]); #ifndef NO_PTHREADS static pthread_mutex_t attr_mutex; -#define attr_lock()pthread_mutex_lock(&attr_mutex) +static inline void attr_lock(void) +{ + static int initialized; + + if (!initialized) { + pthread_mutex_init(&attr_mutex, NULL); + initialized = 1; + } + pthread_mutex_lock(&attr_mutex); +} #define attr_unlock()pthread_mutex_unlock(&attr_mutex) #else