 +				exit(-1);
 +			}
 +			if (pthread_mutexattr_settype(&attr, PTHREAD_MUTEX_RECURSIVE))
-+                        {
-+                                perror("cURL fatal error: Error setting mutex recursive attribute");
-+                                exit(-1);
-+                        }
++			{
++				perror("cURL fatal error: Error setting mutex recursive attribute");
++				exit(-1);
++			}
 +			if (pthread_mutex_init(&mutex_, &attr))
-+                        {
-+                                perror("cURL fatal error: Error initializing mutex");
-+                                exit(-1);
-+                        }
++			{
++				perror("cURL fatal error: Error initializing mutex");
++				exit(-1);
++			}
 +			if (pthread_mutexattr_destroy(&attr))
-+                        {
-+                                perror("cURL fatal error: Error destroying mutex attribute");
-+                                exit(-1);
-+                        }
-+#endif
++			{
++				perror("cURL fatal error: Error destroying mutex attribute");
++				exit(-1);
++			}
++#endif
++			g_cs_initialized = true;
 +		}
 +
 +
 +		inline ~_CriticalSection()
 +		{
++			g_cs_initialized = false;
 +#ifdef _WIN32
 +			DeleteCriticalSection(&cs_);
 +#elif defined VXWORKS_PPC

From 215849695855605bd6f618478dec36220f9ca933 Mon Sep 17 00:00:00 2001
From: Jonathan David <jonathan.david@ni.com>
Date: Thu, 18 Feb 2016 11:30:26 -0600
Subject: [PATCH 10/21] Add mutex locking and unlocking

Include global_mutex.cpp and global_mutex.h to allow for
thread-safe operation. Provides functions for recursive mutex
locking and unlocking.

Upstream-Status: Inappropriate [creates Linux dependency]
---
 lib/global_mutex.cpp | 173 +++++++++++++++++++++++++++++++++++++++++++++++++++
 lib/global_mutex.h   |  18 ++++++
 2 files changed, 191 insertions(+)
 create mode 100644 lib/global_mutex.cpp
 create mode 100644 lib/global_mutex.h

diff --git a/lib/global_mutex.cpp b/lib/global_mutex.cpp
new file mode 100644
index 0000000..d842ece
--- /dev/null
+++ b/lib/global_mutex.cpp
@@ -0,0 +1,173 @@
+/* Implementation of curl_global_mutex_lock() and curl_global_mutex_unlock().
+ * 
+ * @note This C++ source file MUST NOT throw exceptions, use RTTI, or

+			}
+#elif defined(macintosh) || defined(__APPLE__) || defined(__APPLE_CC__)
+			if (pthread_mutex_lock(&mutex_))
+			{
+				perror("cURL fatal error: Error locking mutex");
+				exit(-1);
+			}
+#endif
+		}
+
