summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorMarcel Raad <Marcel.Raad@teamviewer.com>2019-04-05 19:46:05 +0200
committerMarcel Raad <Marcel.Raad@teamviewer.com>2019-04-11 21:08:42 +0200
commitbb0b10135caf58f82ee9e9d38f400880a7e5c9cc (patch)
treeeea3b89cf89e62cde55060f85baebe5db1c50384
parentd250ed4753b74889fb699a9ee638d7d2e48c2b01 (diff)
downloadcurl-bb0b10135caf58f82ee9e9d38f400880a7e5c9cc.tar.gz
polarssl_threadlock: remove conditionally unused code
Make functions no-ops if neither both USE_THREADS_POSIX and HAVE_PTHREAD_H nor both USE_THREADS_WIN32 and HAVE_PROCESS_H are defined. Previously, if only one of them was defined, there was either code compiled that did nothing useful or the wrong header included for the functions used. Also, move POLARSSL_MUTEX_T define to implementation file as it's not used externally. Closes https://github.com/curl/curl/pull/3739
-rw-r--r--lib/vtls/polarssl_threadlock.c43
-rw-r--r--lib/vtls/polarssl_threadlock.h9
2 files changed, 23 insertions, 29 deletions
diff --git a/lib/vtls/polarssl_threadlock.c b/lib/vtls/polarssl_threadlock.c
index dd5fbd7ec..8ef651d40 100644
--- a/lib/vtls/polarssl_threadlock.c
+++ b/lib/vtls/polarssl_threadlock.c
@@ -23,16 +23,15 @@
#include "curl_setup.h"
#if (defined(USE_POLARSSL) || defined(USE_MBEDTLS)) && \
- (defined(USE_THREADS_POSIX) || defined(USE_THREADS_WIN32))
-
-#if defined(USE_THREADS_POSIX)
-# ifdef HAVE_PTHREAD_H
-# include <pthread.h>
-# endif
-#elif defined(USE_THREADS_WIN32)
-# ifdef HAVE_PROCESS_H
-# include <process.h>
-# endif
+ ((defined(USE_THREADS_POSIX) && defined(HAVE_PTHREAD_H)) || \
+ (defined(USE_THREADS_WIN32) && defined(HAVE_PROCESS_H)))
+
+#if defined(USE_THREADS_POSIX) && defined(HAVE_PTHREAD_H)
+# include <pthread.h>
+# define POLARSSL_MUTEX_T pthread_mutex_t
+#elif defined(USE_THREADS_WIN32) && defined(HAVE_PROCESS_H)
+# include <process.h>
+# define POLARSSL_MUTEX_T HANDLE
#endif
#include "polarssl_threadlock.h"
@@ -56,19 +55,19 @@ int Curl_polarsslthreadlock_thread_setup(void)
if(!mutex_buf)
return 0; /* error, no number of threads defined */
-#ifdef HAVE_PTHREAD_H
+#if defined(USE_THREADS_POSIX) && defined(HAVE_PTHREAD_H)
for(i = 0; i < NUMT; i++) {
ret = pthread_mutex_init(&mutex_buf[i], NULL);
if(ret)
return 0; /* pthread_mutex_init failed */
}
-#elif defined(HAVE_PROCESS_H)
+#elif defined(USE_THREADS_WIN32) && defined(HAVE_PROCESS_H)
for(i = 0; i < NUMT; i++) {
mutex_buf[i] = CreateMutex(0, FALSE, 0);
if(mutex_buf[i] == 0)
return 0; /* CreateMutex failed */
}
-#endif /* HAVE_PTHREAD_H */
+#endif /* USE_THREADS_POSIX && HAVE_PTHREAD_H */
return 1; /* OK */
}
@@ -81,19 +80,19 @@ int Curl_polarsslthreadlock_thread_cleanup(void)
if(!mutex_buf)
return 0; /* error, no threads locks defined */
-#ifdef HAVE_PTHREAD_H
+#if defined(USE_THREADS_POSIX) && defined(HAVE_PTHREAD_H)
for(i = 0; i < NUMT; i++) {
ret = pthread_mutex_destroy(&mutex_buf[i]);
if(ret)
return 0; /* pthread_mutex_destroy failed */
}
-#elif defined(HAVE_PROCESS_H)
+#elif defined(USE_THREADS_WIN32) && defined(HAVE_PROCESS_H)
for(i = 0; i < NUMT; i++) {
ret = CloseHandle(mutex_buf[i]);
if(!ret)
return 0; /* CloseHandle failed */
}
-#endif /* HAVE_PTHREAD_H */
+#endif /* USE_THREADS_POSIX && HAVE_PTHREAD_H */
free(mutex_buf);
mutex_buf = NULL;
@@ -103,7 +102,7 @@ int Curl_polarsslthreadlock_thread_cleanup(void)
int Curl_polarsslthreadlock_lock_function(int n)
{
int ret;
-#ifdef HAVE_PTHREAD_H
+#if defined(USE_THREADS_POSIX) && defined(HAVE_PTHREAD_H)
if(n < NUMT) {
ret = pthread_mutex_lock(&mutex_buf[n]);
if(ret) {
@@ -112,7 +111,7 @@ int Curl_polarsslthreadlock_lock_function(int n)
return 0; /* pthread_mutex_lock failed */
}
}
-#elif defined(HAVE_PROCESS_H)
+#elif defined(USE_THREADS_WIN32) && defined(HAVE_PROCESS_H)
if(n < NUMT) {
ret = (WaitForSingleObject(mutex_buf[n], INFINITE) == WAIT_FAILED?1:0);
if(ret) {
@@ -121,14 +120,14 @@ int Curl_polarsslthreadlock_lock_function(int n)
return 0; /* pthread_mutex_lock failed */
}
}
-#endif /* HAVE_PTHREAD_H */
+#endif /* USE_THREADS_POSIX && HAVE_PTHREAD_H */
return 1; /* OK */
}
int Curl_polarsslthreadlock_unlock_function(int n)
{
int ret;
-#ifdef HAVE_PTHREAD_H
+#if defined(USE_THREADS_POSIX) && defined(HAVE_PTHREAD_H)
if(n < NUMT) {
ret = pthread_mutex_unlock(&mutex_buf[n]);
if(ret) {
@@ -137,7 +136,7 @@ int Curl_polarsslthreadlock_unlock_function(int n)
return 0; /* pthread_mutex_unlock failed */
}
}
-#elif defined(HAVE_PROCESS_H)
+#elif defined(USE_THREADS_WIN32) && defined(HAVE_PROCESS_H)
if(n < NUMT) {
ret = ReleaseMutex(mutex_buf[n]);
if(!ret) {
@@ -146,7 +145,7 @@ int Curl_polarsslthreadlock_unlock_function(int n)
return 0; /* pthread_mutex_lock failed */
}
}
-#endif /* HAVE_PTHREAD_H */
+#endif /* USE_THREADS_POSIX && HAVE_PTHREAD_H */
return 1; /* OK */
}
diff --git a/lib/vtls/polarssl_threadlock.h b/lib/vtls/polarssl_threadlock.h
index dda5359b8..122647528 100644
--- a/lib/vtls/polarssl_threadlock.h
+++ b/lib/vtls/polarssl_threadlock.h
@@ -26,13 +26,8 @@
#if (defined USE_POLARSSL) || (defined USE_MBEDTLS)
-#if defined(USE_THREADS_POSIX)
-# define POLARSSL_MUTEX_T pthread_mutex_t
-#elif defined(USE_THREADS_WIN32)
-# define POLARSSL_MUTEX_T HANDLE
-#endif
-
-#if defined(USE_THREADS_POSIX) || defined(USE_THREADS_WIN32)
+#if (defined(USE_THREADS_POSIX) && defined(HAVE_PTHREAD_H)) || \
+ (defined(USE_THREADS_WIN32) && defined(HAVE_PROCESS_H))
int Curl_polarsslthreadlock_thread_setup(void);
int Curl_polarsslthreadlock_thread_cleanup(void);