Skip to content

Instantly share code, notes, and snippets.

@errzey
Created November 18, 2010 02:42
Show Gist options
  • Save errzey/704551 to your computer and use it in GitHub Desktop.
Save errzey/704551 to your computer and use it in GitHub Desktop.
pthread_mutex_t *thread_locks;
unsigned long
openssl_thread_id(void) {
return (unsigned long) pthread_self();
}
void
openssl_thread_lock( int mode, int lock_id, const char* file, int line ) {
if ( mode & CRYPTO_LOCK )
pthread_mutex_lock( &thread_locks[lock_id] );
else
pthread_mutex_unlock( &thread_locks[lock_id] );
}
void init_ssl_lock(void) {
int num_thread_locks = CRYPTO_num_locks();
thread_locks = calloc( sizeof( pthread_mutex_t ), num_thread_locks );
for (i = 0; i < num_thread_locks; i++)
{
if ( pthread_mutex_init( &thread_locks[i], NULL ) )
{
fprintf(stderr, "Unable to create mutex\n");
exit(80);
}
}
CRYPTO_set_locking_callback( &openssl_thread_lock );
CRYPTO_set_id_callback( &openssl_thread_id );
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment