-// libcurl with openssl needs locking_function and thread id for threadsafe
-// https://curl.haxx.se/libcurl/c/threadsafe.html
-// https://www.openssl.org/docs/man1.0.2/crypto/threads.html#DESCRIPTION
-void CurlEnvironment::OnOpenSSLLocking( int mode, int n, const char* file, int line )
-{
- if( mode & CRYPTO_LOCK )
- {
- mMutexs[n].lock();
- }
- else
- {
- mMutexs[n].unlock();
- }
-}
-
-void CurlEnvironment::GetThreadId( CRYPTO_THREADID* tid )
-{
- // If dali uses c++ thread, we may replace pthread_self() to this_thread::get_id()
- CRYPTO_THREADID_set_numeric( tid, static_cast< unsigned long > ( pthread_self() ) );
-}
-
-void CurlEnvironment::SetLockingFunction()
-{
- if( mMutexs != NULL )
- {
- return;
- }
-
- mMutexs = new std::mutex[ CRYPTO_num_locks() ];
-
- CRYPTO_THREADID_set_callback( &CurlEnvironment::GetThreadId );
- CRYPTO_set_locking_callback( &CurlEnvironment::OnOpenSSLLocking );
-}
-
-void CurlEnvironment::UnsetLockingFunction()
-{
- if( mMutexs == NULL )
- {
- return;
- }
-
- CRYPTO_THREADID_set_callback( NULL );
- CRYPTO_set_locking_callback( NULL );
- delete [] mMutexs;
- mMutexs = NULL;
-}
-