]> git.ipfire.org Git - thirdparty/gnutls.git/commitdiff
simplified locking code. Locking functions always exist but are dummies if no
authorNikos Mavrogiannopoulos <nmav@gnutls.org>
Tue, 29 Jun 2010 16:12:44 +0000 (18:12 +0200)
committerNikos Mavrogiannopoulos <nmav@gnutls.org>
Tue, 29 Jun 2010 16:16:36 +0000 (18:16 +0200)
locks have been set.

lib/locks.c
lib/locks.h
lib/nettle/rnd.c

index 336fe1c1c1ece72d8b5dc0bf51c8cc2887b0a6d8..c017fc1686f05d62116c307d8527ca3d8ef387e3 100644 (file)
 #include <libtasn1.h>
 #include <gnutls_dh.h>
 #include <random.h>
-#ifndef HAVE_LIBNETTLE
-#include <gcrypt.h>
 
-#endif
+#include <locks.h>
 
-#ifdef _WIN32
+#ifdef HAVE_WIN32_LOCKS
 
 # include <windows.h>
 
@@ -71,10 +69,10 @@ static int gnutls_system_mutex_unlock (void *priv)
   return 0;
 }
 
-#else
+#endif /* WIN32_LOCKS */
 
-# ifdef HAVE_LIBPTHREAD
-#  include <pthread.h>
+#ifdef HAVE_PTHREAD_LOCKS
+# include <pthread.h>
 
 static int gnutls_system_mutex_init (void **priv)
 {
@@ -125,16 +123,31 @@ static int gnutls_system_mutex_unlock (void *priv)
   return 0;
 }
 
-# else
+#endif /* PTHREAD_LOCKS */
 
-#define gnutls_system_mutex_init NULL
-#define gnutls_system_mutex_deinit NULL
-#define gnutls_system_mutex_lock NULL
-#define gnutls_mutex_unlock NULL
+#ifdef HAVE_NO_LOCKS
 
-# endif /* PTHREAD */
+static int gnutls_system_mutex_init (void **priv)
+{
+  return 0;
+}
+
+static void gnutls_system_mutex_deinit (void *priv)
+{
+  return;
+}
+
+static int gnutls_system_mutex_lock (void *priv)
+{
+  return 0;
+}
+
+static int gnutls_system_mutex_unlock (void *priv)
+{
+  return 0;
+}
 
-#endif
+#endif /* NO_LOCKS */
 
 mutex_init_func gnutls_mutex_init = gnutls_system_mutex_init;
 mutex_deinit_func gnutls_mutex_deinit = gnutls_system_mutex_deinit;
index 0a91d2ffece9e449243559082688bac1cca4f89a..f76b962e58d60c716f755789bc8ec7b02b02d685 100644 (file)
@@ -4,6 +4,16 @@
 #include <gnutls/gnutls.h>
 #include <gnutls_int.h>
 
+#ifdef _WIN32
+# define HAVE_WIN32_LOCKS
+#else
+# ifdef HAVE_LIBPTHREAD
+#  define HAVE_PTHREAD_LOCKS
+# else
+#  define HAVE_NO_LOCKS
+# endif
+#endif
+
 extern mutex_init_func gnutls_mutex_init;
 extern mutex_deinit_func gnutls_mutex_deinit;
 extern mutex_lock_func gnutls_mutex_lock;
index ac24235991b0e9255ffdb20724ced5752feca9d2..169049dba8e5157678a7d3920b20f1facab27826 100644 (file)
@@ -41,8 +41,8 @@
 
 static void* rnd_mutex;
 
-#define RND_LOCK if (gnutls_mutex_lock && gnutls_mutex_lock(&rnd_mutex)!=0) abort()
-#define RND_UNLOCK if (gnutls_mutex_unlock && gnutls_mutex_unlock(&rnd_mutex)!=0) abort()
+#define RND_LOCK if (gnutls_mutex_lock(&rnd_mutex)!=0) abort()
+#define RND_UNLOCK if (gnutls_mutex_unlock(&rnd_mutex)!=0) abort()
 
 enum {
        RANDOM_SOURCE_TRIVIA=0,