 +	{
 +		// Do NOT add try/catch blocks here. See comments above for details.
 +#if defined(_WIN32) || defined(VXWORKS_PPC) || defined(macintosh) || defined(__APPLE__) || defined(__APPLE_CC__)
-+		g_cs.lock();
++		if (g_cs_initialized)
++		{
++			g_cs.lock();
++		}
 +#elif defined(linux) || defined(__linux__) || defined(__gnu_linux__) || defined(__linux)
-+                if (pthread_mutex_lock(&mutex_))
-+                {
-+                        perror("cURL fatal error: Error locking mutex");
-+                        exit(-1);
-+                }
++		if (pthread_mutex_lock(&mutex_))
++		{
++			perror("cURL fatal error: Error locking mutex");
++			exit(-1);
++		}
 +#endif
 +	}
 +

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

+	{
+		// Do NOT add try/catch blocks here. See comments above for details.
+#if defined(_WIN32) || defined(VXWORKS_PPC) || defined(macintosh) || defined(__APPLE__) || defined(__APPLE_CC__)
+		if (g_cs_initialized)
+		{
+			g_cs.unlock();
+		}
+#elif defined(linux) || defined(__linux__) || defined(__gnu_linux__) || defined(__linux)
+		if (pthread_mutex_unlock(&mutex_))
+		{
+			perror("cURL fatal error: Error unlocking mutex");
+			exit(-1);
+		}
+#endif
+	}
+}
diff --git a/lib/global_mutex.h b/lib/global_mutex.h
new file mode 100644
index 0000000000000000000000000000000000000000..87aae31e5865b6199aab4eb984c2a2ff9ffadefd
--- /dev/null
+++ b/lib/global_mutex.h
@@ -0,0 +1,18 @@
