From: Nikos Mavrogiannopoulos Date: Tue, 29 Jun 2010 16:12:44 +0000 (+0200) Subject: simplified locking code. Locking functions always exist but are dummies if no X-Git-Tag: gnutls_2_11_3~133 X-Git-Url: http://git.ipfire.org/gitweb.cgi?a=commitdiff_plain;h=16aa46b90da439cd992f4067394b6f8cb4cbb1ad;p=thirdparty%2Fgnutls.git simplified locking code. Locking functions always exist but are dummies if no locks have been set. --- diff --git a/lib/locks.c b/lib/locks.c index 336fe1c1c1..c017fc1686 100644 --- a/lib/locks.c +++ b/lib/locks.c @@ -28,12 +28,10 @@ #include #include #include -#ifndef HAVE_LIBNETTLE -#include -#endif +#include -#ifdef _WIN32 +#ifdef HAVE_WIN32_LOCKS # include @@ -71,10 +69,10 @@ static int gnutls_system_mutex_unlock (void *priv) return 0; } -#else +#endif /* WIN32_LOCKS */ -# ifdef HAVE_LIBPTHREAD -# include +#ifdef HAVE_PTHREAD_LOCKS +# include 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; diff --git a/lib/locks.h b/lib/locks.h index 0a91d2ffec..f76b962e58 100644 --- a/lib/locks.h +++ b/lib/locks.h @@ -4,6 +4,16 @@ #include #include +#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; diff --git a/lib/nettle/rnd.c b/lib/nettle/rnd.c index ac24235991..169049dba8 100644 --- a/lib/nettle/rnd.c +++ b/lib/nettle/rnd.c @@ -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,