PolarSSL: WIN32 threading support for entropy
Added WIN32 threading support for PolarSSL entropy if --enable-threaded-resolver config flag is set and process.h can be found.
This commit is contained in:
parent
c35a10483d
commit
f10006ee5f
@ -68,10 +68,10 @@
|
||||
#include "rawstr.h"
|
||||
|
||||
/* apply threading? */
|
||||
#if defined(USE_THREADS_POSIX)
|
||||
#if defined(USE_THREADS_POSIX) || defined(USE_THREADS_WIN32)
|
||||
#define THREADING_SUPPORT
|
||||
#include "polarsslthreadlock.h"
|
||||
#endif /* USE_THREADS_POSIX */
|
||||
#endif /* USE_THREADS_POSIX || USE_THREADS_WIN32 */
|
||||
|
||||
#define _MPRINTF_REPLACE /* use our functions only */
|
||||
#include <curl/mprintf.h>
|
||||
|
@ -24,13 +24,18 @@
|
||||
#include <stdio.h>
|
||||
#include "curl_setup.h"
|
||||
|
||||
#ifdef USE_POLARSSL
|
||||
#if defined(USE_POLARSSL) && (defined(USE_THREADS_POSIX) || defined(USE_THREADS_WIN32))
|
||||
|
||||
#if defined(USE_THREADS_POSIX)
|
||||
#ifdef HAVE_PTHREAD_H
|
||||
#include <pthread.h>
|
||||
#define MUTEX_TYPE pthread_mutex_t
|
||||
#endif /* HAVE_PTHREAD_H */
|
||||
#elif defined(USE_THREADS_WIN32)
|
||||
#ifdef HAVE_PROCESS_H
|
||||
#include <process.h>
|
||||
#define MUTEX_TYPE HANDLE
|
||||
#endif /* HAVE_PROCESS_H */
|
||||
#endif /* USE_THREADS_POSIX */
|
||||
|
||||
#include "polarsslthreadlock.h"
|
||||
@ -57,6 +62,13 @@ int polarsslthreadlock_thread_setup(void)
|
||||
if(ret)
|
||||
return 0; /* pthread_mutex_init failed */
|
||||
}
|
||||
#elif 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 */
|
||||
|
||||
return 1; /* OK */
|
||||
@ -75,8 +87,13 @@ int polarsslthreadlock_thread_cleanup(void)
|
||||
{
|
||||
ret = pthread_mutex_destroy(&mutex_buf[i]);
|
||||
if(ret)
|
||||
return 0; /* pthread_mutex_destroy failed */
|
||||
}
|
||||
return 0; /* pthread_mutex_destroy failed */
|
||||
}
|
||||
#elif 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 */
|
||||
free(mutex_buf);
|
||||
mutex_buf = NULL;
|
||||
@ -93,10 +110,20 @@ int polarsslthreadlock_lock_function(int n)
|
||||
ret = pthread_mutex_lock(&mutex_buf[n]);
|
||||
if(ret)
|
||||
{
|
||||
DEBUGF(fprintf(stderr, "Error: pthread_mutex_lock failed\n"));
|
||||
DEBUGF(fprintf(stderr, "Error: polarsslthreadlock_lock_function failed\n"));
|
||||
return 0; /* pthread_mutex_lock failed */
|
||||
}
|
||||
}
|
||||
}
|
||||
#elif defined(HAVE_PROCESS_H)
|
||||
if(n < NUMT)
|
||||
{
|
||||
ret = (WaitForSingleObject(mutex_buf[n], INFINITE)==WAIT_FAILED?1:0);
|
||||
if(ret)
|
||||
{
|
||||
DEBUGF(fprintf(stderr, "Error: polarsslthreadlock_lock_function failed\n"));
|
||||
return 0; /* pthread_mutex_lock failed */
|
||||
}
|
||||
}
|
||||
#endif /* HAVE_PTHREAD_H */
|
||||
return 1; /* OK */
|
||||
}
|
||||
@ -110,10 +137,20 @@ int polarsslthreadlock_unlock_function(int n)
|
||||
ret = pthread_mutex_unlock(&mutex_buf[n]);
|
||||
if(ret)
|
||||
{
|
||||
DEBUGF(fprintf(stderr, "Error: pthread_mutex_unlock failed\n"));
|
||||
DEBUGF(fprintf(stderr, "Error: polarsslthreadlock_unlock_function failed\n"));
|
||||
return 0; /* pthread_mutex_unlock failed */
|
||||
}
|
||||
}
|
||||
#elif defined(HAVE_PROCESS_H)
|
||||
if(n < NUMT)
|
||||
{
|
||||
ret = ReleaseMutex(mutex_buf[n]);
|
||||
if(!ret)
|
||||
{
|
||||
DEBUGF(fprintf(stderr, "Error: polarsslthreadlock_unlock_function failed\n"));
|
||||
return 0; /* pthread_mutex_lock failed */
|
||||
}
|
||||
}
|
||||
#endif /* HAVE_PTHREAD_H */
|
||||
return 1; /* OK */
|
||||
}
|
||||
|
Loading…
x
Reference in New Issue
Block a user