some more work on threading but not complete yet
Этот коммит содержится в:
родитель
bcc2d8474c
Коммит
50d8d75d89
@ -32,63 +32,90 @@
|
|||||||
|
|
||||||
|
|
||||||
#ifdef HAVE_LIBGCRYPT
|
#ifdef HAVE_LIBGCRYPT
|
||||||
|
#define HAVE_PTHREADS
|
||||||
|
#ifdef HAVE_PTHREADS
|
||||||
#include <errno.h>
|
#include <errno.h>
|
||||||
#include <pthread.h>
|
#include <pthread.h>
|
||||||
|
|
||||||
static int gcry_pthread_mutex_init (void **priv){
|
static int ssh_pthread_mutex_init (void **priv){
|
||||||
int err = 0;
|
int err = 0;
|
||||||
pthread_mutex_t *lock = malloc (sizeof (pthread_mutex_t));
|
*priv = malloc (sizeof (pthread_mutex_t));
|
||||||
|
|
||||||
if (!lock)
|
if (*priv==NULL)
|
||||||
err = ENOMEM;
|
return ENOMEM;
|
||||||
if (!err)
|
err = pthread_mutex_init (*priv, NULL);
|
||||||
{
|
if (err != 0){
|
||||||
err = pthread_mutex_init (lock, NULL);
|
free (*priv);
|
||||||
if (err)
|
*priv=NULL;
|
||||||
free (lock);
|
|
||||||
else
|
|
||||||
*priv = lock;
|
|
||||||
}
|
}
|
||||||
return err;
|
return err;
|
||||||
}
|
}
|
||||||
|
|
||||||
static int gcry_pthread_mutex_destroy (void **lock) {
|
static int ssh_pthread_mutex_destroy (void **lock) {
|
||||||
int err = pthread_mutex_destroy ((pthread_mutex_t*)*lock);
|
int err = pthread_mutex_destroy (*lock);
|
||||||
free (*lock);
|
free (*lock);
|
||||||
|
*lock=NULL;
|
||||||
return err;
|
return err;
|
||||||
}
|
}
|
||||||
static int gcry_pthread_mutex_lock (void **lock) {
|
|
||||||
return pthread_mutex_lock ((pthread_mutex_t*)*lock);
|
static int ssh_pthread_mutex_lock (void **lock) {
|
||||||
|
return pthread_mutex_lock (*lock);
|
||||||
}
|
}
|
||||||
static int gcry_pthread_mutex_unlock (void **lock){
|
|
||||||
return pthread_mutex_unlock ((pthread_mutex_t*)*lock);
|
static int ssh_pthread_mutex_unlock (void **lock){
|
||||||
|
return pthread_mutex_unlock (*lock);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
static struct gcry_thread_cbs gcrypt_threads=
|
static struct ssh_threads_callbacks_struct ssh_gcrypt_user_callbacks=
|
||||||
{
|
{
|
||||||
.option=GCRY_THREAD_OPTION_VERSION << 8 || GCRY_THREAD_OPTION_PTHREAD,
|
.mutex_init=ssh_pthread_mutex_init,
|
||||||
.mutex_init=gcry_pthread_mutex_init,
|
.mutex_destroy=ssh_pthread_mutex_destroy,
|
||||||
.mutex_destroy=gcry_pthread_mutex_destroy,
|
.mutex_lock=ssh_pthread_mutex_lock,
|
||||||
.mutex_lock=gcry_pthread_mutex_lock,
|
.mutex_unlock=ssh_pthread_mutex_unlock
|
||||||
.mutex_unlock=gcry_pthread_mutex_unlock
|
|
||||||
};
|
};
|
||||||
|
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
|
static struct gcry_thread_cbs gcrypt_threads_callbacks;
|
||||||
|
|
||||||
|
#endif
|
||||||
|
|
||||||
static struct ssh_threads_callbacks_struct *user_callbacks;
|
static struct ssh_threads_callbacks_struct *user_callbacks;
|
||||||
|
|
||||||
|
#ifdef HAVE_LIBGCRYPT
|
||||||
|
static void copy_callback(struct ssh_threads_callbacks_struct *cb){
|
||||||
|
gcrypt_threads_callbacks.option= GCRY_THREAD_OPTION_VERSION << 8 || GCRY_THREAD_OPTION_USER;
|
||||||
|
gcrypt_threads_callbacks.mutex_init=cb->mutex_init;
|
||||||
|
gcrypt_threads_callbacks.mutex_destroy=cb->mutex_destroy;
|
||||||
|
gcrypt_threads_callbacks.mutex_lock=cb->mutex_lock;
|
||||||
|
gcrypt_threads_callbacks.mutex_unlock=cb->mutex_unlock;
|
||||||
|
}
|
||||||
|
#endif
|
||||||
|
|
||||||
/** @internal
|
/** @internal
|
||||||
* @brief inits the threading with the backend cryptographic libraries
|
* @brief inits the threading with the backend cryptographic libraries
|
||||||
*/
|
*/
|
||||||
|
|
||||||
int ssh_threads_init(void){
|
int ssh_threads_init(void){
|
||||||
#ifdef HAVE_LIBGCRYPT
|
#ifdef HAVE_LIBGCRYPT
|
||||||
gcry_control(GCRYCTL_SET_THREAD_CBS, &gcrypt_threads);
|
if(user_callbacks != NULL){
|
||||||
|
copy_callback(user_callbacks);
|
||||||
|
gcry_control(GCRYCTL_SET_THREAD_CBS, &gcrypt_threads_callbacks);
|
||||||
|
return SSH_OK;
|
||||||
|
}
|
||||||
|
#ifdef HAVE_PTHREADS
|
||||||
|
else {
|
||||||
|
copy_callback(&ssh_gcrypt_user_callbacks);
|
||||||
|
gcry_control(GCRYCTL_SET_THREAD_CBS, &gcrypt_threads_callbacks);
|
||||||
|
return SSH_OK;
|
||||||
|
}
|
||||||
|
#endif
|
||||||
#else
|
#else
|
||||||
|
|
||||||
|
|
||||||
#endif
|
#endif
|
||||||
return 0;
|
return SSH_ERROR;
|
||||||
}
|
}
|
||||||
|
|
||||||
int ssh_init_set_threads_callbacks(struct ssh_threads_callbacks_struct *cb){
|
int ssh_init_set_threads_callbacks(struct ssh_threads_callbacks_struct *cb){
|
||||||
|
@ -3,8 +3,8 @@
|
|||||||
#include <pthread.h>
|
#include <pthread.h>
|
||||||
#include "torture.h"
|
#include "torture.h"
|
||||||
|
|
||||||
#define NUM_LOOPS 50000
|
#define NUM_LOOPS 1000
|
||||||
#define NUM_THREADS 200
|
#define NUM_THREADS 100
|
||||||
|
|
||||||
static void setup(){
|
static void setup(){
|
||||||
ssh_init();
|
ssh_init();
|
||||||
|
Загрузка…
x
Ссылка в новой задаче
Block a user