Re: [PATCH 27/36] attr: convert to new threadsafe API

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



Hi Stefan,

On Sat, 22 Oct 2016, Stefan Beller wrote:

> @@ -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




[Index of Archives]     [Linux Kernel Development]     [Gcc Help]     [IETF Annouce]     [DCCP]     [Netdev]     [Networking]     [Security]     [V4L]     [Bugtraq]     [Yosemite]     [MIPS Linux]     [ARM Linux]     [Linux Security]     [Linux RAID]     [Linux SCSI]     [Fedora Users]