Multithreading OpenSSL线程和Helgrind

Multithreading OpenSSL线程和Helgrind,multithreading,openssl,valgrind,Multithreading,Openssl,Valgrind,我正在实现一个多线程应用程序,它广泛使用OpenSSL加密库 我在这里(,)、网站(eg)和OpenSSL源代码中包含的crypto/threads/mttest.c程序中主要是示例代码中遵循了一些指导原则。其中引用的示例主要处理OpenSSL的静态锁回调函数。但是,根据OpenSSL文档()和(第255-259页),有时可能需要定义一些用于动态锁管理的函数 因此,我实现了初始化和清理功能,设置了两种类型的锁管理功能(静态和动态)。这些功能如下: static unsigned long _th

我正在实现一个多线程应用程序,它广泛使用OpenSSL加密库

我在这里(,)、网站(eg)和OpenSSL源代码中包含的crypto/threads/mttest.c程序中主要是示例代码中遵循了一些指导原则。其中引用的示例主要处理OpenSSL的静态锁回调函数。但是,根据OpenSSL文档()和(第255-259页),有时可能需要定义一些用于动态锁管理的函数

因此,我实现了初始化和清理功能,设置了两种类型的锁管理功能(静态和动态)。这些功能如下:

static unsigned long _thread_id_function(void) {
  return ((unsigned long) pthread_self());
}

static void _locking_function(int mode, int id, const char *file, int line) {
  if(mode & CRYPTO_LOCK) {
    pthread_mutex_lock(&mutex_buffer[id]);
  } else {
    pthread_mutex_unlock(&mutex_buffer[id]);
  }
}

static struct CRYPTO_dynlock_value* _dyn_create_func(const char *file, int line) {
  struct CRYPTO_dynlock_value *value;
  value = (struct CRYPTO_dynlock_value *) malloc(sizeof(struct CRYPTO_dynlock_value));
  pthread_mutex_init(&value->mutex,NULL);
  return value;
}

static void _dyn_destroy_func(struct CRYPTO_dynlock_value *l, 
  const char *file, int line) {
  pthread_mutex_destroy(&l->mutex);
  free(l);
  return;
}

static void _dyn_lock_func(int mode, struct CRYPTO_dynlock_value *l,
  const char *file, int line) {
  if(mode & CRYPTO_LOCK) {
    pthread_mutex_lock(&l->mutex);
  } else {
    pthread_mutex_unlock(&l->mutex);
  }
}

static int _static_init() {

  int i;

  mutex_buffer = (pthread_mutex_t *) malloc(CRYPTO_num_locks()*sizeof(pthread_mutex_t));

  for(i=0; i<CRYPTO_num_locks(); i++) {
    pthread_mutex_init(&mutex_buffer[i], NULL);
  }

  CRYPTO_set_id_callback(_thread_id_function);
  CRYPTO_set_locking_callback(_locking_function);

  return 0;

}

static int _static_cleanup() {

  int i;

  CRYPTO_set_id_callback(NULL);
  CRYPTO_set_locking_callback(NULL);

  for(i=0; i<CRYPTO_num_locks(); i++) {
    pthread_mutex_destroy(&mutex_buffer[i]);
  }

  free(mutex_buffer); mutex_buffer = NULL;
  return 0;
}

static int _dyn_init() {
  CRYPTO_set_dynlock_create_callback(_dyn_create_func);
  CRYPTO_set_dynlock_lock_callback(_dyn_lock_func);
  CRYPTO_set_dynlock_destroy_callback(_dyn_destroy_func);
  return 0;
}

static int _dyn_cleanup() {
  CRYPTO_set_dynlock_create_callback(NULL);
  CRYPTO_set_dynlock_lock_callback(NULL);
  CRYPTO_set_dynlock_destroy_callback(NULL);
  return 0;
}

int cryptothread_init() {
  _static_init();
  _dyn_init();
  return 0;
}

int cryptothread_cleanup() {
  _static_cleanup();
  _dyn_cleanup();
  return 0;
}
静态无符号长线程id函数(void){
返回((无符号长)pthread_self());
}
静态无效锁定函数(int模式、int id、const char*文件、int行){
if(模式和加密锁){
pthread_mutex_lock(&mutex_buffer[id]);
}否则{
pthread_mutex_unlock(&mutex_buffer[id]);
}
}
静态结构加密\动态锁定\值*\动态\创建\函数(常量字符*文件,int行){
结构加密_dynlock_值*值;
value=(struct CRYPTO_dynlock_value*)malloc(sizeof(struct CRYPTO_dynlock_value));
pthread_mutex_init(&value->mutex,NULL);
返回值;
}
静态void _dyn _destroy _func(结构加密_dynlock)值*l,
常量字符*文件,整数行){
pthread_mutex_destroy(&l->mutex);
免费(l);
返回;
}
静态void\u dyn\u lock\u func(int模式,结构加密\u dynlock\u值*l,
常量字符*文件,整数行){
if(模式和加密锁){
pthread_mutex_lock(&l->mutex);
}否则{
pthread_mutex_unlock(&l->mutex);
}
}
static int_static_init(){
int i;
mutex_buffer=(pthread_mutex_t*)mallock(CRYPTO_num_locks()*sizeof(pthread_mutex_t));

对于(i=0;我也看到了这一点……您是否曾经决定如何配置OpenSSL和valgrind来解析或屏蔽这些报告?