-#ifdef __FEATURE_OPEN_SSL_MULTIHREAD_HANDLE__
-
-#include <openssl/crypto.h>
-
-#define MAX_THREAD_NUMBER 100
-
-static pthread_mutex_t *lock_cs;
-static long *lock_count;
-
-void pthreads_locking_callback(int mode, int type, char *file, int line)
-{
- if (mode & CRYPTO_LOCK) {
- pthread_mutex_lock(&(lock_cs[type]));
- lock_count[type]++;
- } else {
- pthread_mutex_unlock(&(lock_cs[type]));
- }
-}
-
-unsigned long pthreads_thread_id(void)
-{
- return (unsigned long)pthread_self();
-}
-
-INTERNAL_FUNC void emdaemon_setup_handler_for_open_ssl_multithread(void)
-{
- EM_DEBUG_FUNC_BEGIN();
- int i = 0;
-
- lock_cs = OPENSSL_malloc(CRYPTO_num_locks() * sizeof(pthread_mutex_t));
- lock_count = OPENSSL_malloc(CRYPTO_num_locks() * sizeof(long));
-
- for (i = 0; i < CRYPTO_num_locks(); i++) {
- lock_count[i] = 0;
- pthread_mutex_init(&(lock_cs[i]), NULL);
- }
-
- CRYPTO_set_id_callback((unsigned long (*)())pthreads_thread_id);
- CRYPTO_set_locking_callback((void (*)())pthreads_locking_callback);
- EM_DEBUG_FUNC_END();
-}
-
-INTERNAL_FUNC void emdaemon_cleanup_handler_for_open_ssl_multithread(void)
-{
- EM_DEBUG_FUNC_BEGIN();
- int i = 0;
-
- CRYPTO_set_locking_callback(NULL);
- for (i = 0; i < CRYPTO_num_locks(); i++) {
- pthread_mutex_destroy(&(lock_cs[i]));
- EM_DEBUG_LOG("%8ld:%s", lock_count[i], CRYPTO_get_lock_name(i));
- }
- OPENSSL_free(lock_cs);
- OPENSSL_free(lock_count);
-
- EM_DEBUG_FUNC_END();
-}
-
-#endif /* __FEATURE_OPEN_SSL_MULTIHREAD_HANDLE__ */
-