Ticket #114: lock.patch

File lock.patch, 1.2 KB (added by stoecker, 5 years ago)
  • src/main.c

     
    128128server_info_t info;
    129129struct in_addr localaddr;
    130130
     131#ifdef HAVE_TLS
     132#if OPENSSL_VERSION_NUMBER < 0x10100000L
     133static pthread_mutex_t *lock_cs;
     134void pthreads_locking_callback(int mode, int type, char *file, int line)
     135{
     136  if(mode & CRYPTO_LOCK)
     137    pthread_mutex_lock(&(lock_cs[type]));
     138  else
     139    pthread_mutex_unlock(&(lock_cs[type]));
     140}
     141
     142unsigned long pthreads_thread_id(void)
     143{
     144  return (unsigned long)pthread_self();
     145}
     146#endif
     147#endif /* HAVE_TLS */
     148
    131149/*
    132150 * The world starts here.
    133151 * - First initialize the run path and
     
    157175#if OPENSSL_VERSION_NUMBER < 0x10100000L
    158176  SSL_library_init();
    159177  SSL_load_error_strings();
     178  if((lock_cs = OPENSSL_malloc(CRYPTO_num_locks() * sizeof(pthread_mutex_t))))
     179  {
     180    int i;
     181    for (i = 0; i < CRYPTO_num_locks(); i++)
     182      pthread_mutex_init(&(lock_cs[i]), NULL);
     183    CRYPTO_set_id_callback((unsigned long (*)())pthreads_thread_id);
     184    CRYPTO_set_locking_callback((void (*)())pthreads_locking_callback);
     185  }
    160186#endif
    161187#endif /* HAVE_TLS */
    162188