2 #include <crypto/openssl_compat.h> 3 #include <openssl/ssl.h> 6 #if AKTUALIZR_OPENSSL_PRE_11 7 static pthread_mutex_t *lock_cs;
8 static long *lock_count;
13 void pthreads_locking_callback(
int mode,
int type,
const char *,
int) {
15 fprintf(stderr,
"thread=%4d mode=%s lock=%s %s:%d\n",
17 (mode & CRYPTO_LOCK) ?
"l" :
"u",
18 (type & CRYPTO_READ) ?
"r" :
"w", file, line);
21 if (CRYPTO_LOCK_SSL_CERT == type)
22 fprintf(stderr,
"(t,m,f,l) %ld %d %s %d\n",
23 CRYPTO_thread_id(), mode, file, line);
25 if (mode & CRYPTO_LOCK) {
26 pthread_mutex_lock(&(lock_cs[type]));
29 pthread_mutex_unlock(&(lock_cs[type]));
33 unsigned long pthreads_thread_id(
void) {
36 ret = (
unsigned long)pthread_self();
40 void openssl_callbacks_setup(
void) {
44 (pthread_mutex_t *)OPENSSL_malloc(static_cast<int>((
unsigned long)CRYPTO_num_locks() *
sizeof(pthread_mutex_t)));
45 lock_count = (
long *)OPENSSL_malloc(static_cast<int>((
unsigned long)CRYPTO_num_locks() *
sizeof(long)));
46 if (!lock_cs || !lock_count) {
48 if (lock_cs) OPENSSL_free(lock_cs);
49 if (lock_count) OPENSSL_free(lock_count);
52 for (i = 0; i < CRYPTO_num_locks(); i++) {
54 pthread_mutex_init(&(lock_cs[i]), NULL);
57 CRYPTO_set_id_callback((
unsigned long (*)())pthreads_thread_id);
58 CRYPTO_set_locking_callback(pthreads_locking_callback);
61 void openssl_callbacks_cleanup(
void) {
64 CRYPTO_set_locking_callback(NULL);
65 for (i = 0; i < CRYPTO_num_locks(); i++) {
66 pthread_mutex_destroy(&(lock_cs[i]));
68 OPENSSL_free(lock_cs);
69 OPENSSL_free(lock_count);
72 void openssl_callbacks_setup(
void){};
73 void openssl_callbacks_cleanup(
void){};