1
1

some more work on threading but not complete yet

Этот коммит содержится в:
Aris Adamantiadis 2010-08-31 16:49:55 +02:00
родитель bcc2d8474c
Коммит 50d8d75d89
2 изменённых файлов: 54 добавлений и 27 удалений

Просмотреть файл

@ -32,63 +32,90 @@
#ifdef HAVE_LIBGCRYPT
#define HAVE_PTHREADS
#ifdef HAVE_PTHREADS
#include <errno.h>
#include <pthread.h>
static int gcry_pthread_mutex_init (void **priv){
static int ssh_pthread_mutex_init (void **priv){
int err = 0;
pthread_mutex_t *lock = malloc (sizeof (pthread_mutex_t));
*priv = malloc (sizeof (pthread_mutex_t));
if (!lock)
err = ENOMEM;
if (!err)
{
err = pthread_mutex_init (lock, NULL);
if (err)
free (lock);
else
*priv = lock;
if (*priv==NULL)
return ENOMEM;
err = pthread_mutex_init (*priv, NULL);
if (err != 0){
free (*priv);
*priv=NULL;
}
return err;
}
static int gcry_pthread_mutex_destroy (void **lock) {
int err = pthread_mutex_destroy ((pthread_mutex_t*)*lock);
static int ssh_pthread_mutex_destroy (void **lock) {
int err = pthread_mutex_destroy (*lock);
free (*lock);
*lock=NULL;
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=gcry_pthread_mutex_init,
.mutex_destroy=gcry_pthread_mutex_destroy,
.mutex_lock=gcry_pthread_mutex_lock,
.mutex_unlock=gcry_pthread_mutex_unlock
.mutex_init=ssh_pthread_mutex_init,
.mutex_destroy=ssh_pthread_mutex_destroy,
.mutex_lock=ssh_pthread_mutex_lock,
.mutex_unlock=ssh_pthread_mutex_unlock
};
#endif
static struct gcry_thread_cbs gcrypt_threads_callbacks;
#endif
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
* @brief inits the threading with the backend cryptographic libraries
*/
int ssh_threads_init(void){
#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
#endif
return 0;
return SSH_ERROR;
}
int ssh_init_set_threads_callbacks(struct ssh_threads_callbacks_struct *cb){

Просмотреть файл

@ -3,8 +3,8 @@
#include <pthread.h>
#include "torture.h"
#define NUM_LOOPS 50000
#define NUM_THREADS 200
#define NUM_LOOPS 1000
#define NUM_THREADS 100
static void setup(){
ssh_init();