This code stores all objects in the memory allocated by “OPELSSL_malloc”. However, as of now, “OPENSSL_malloc” is equivalent to “malloc”, so you may not need to do so far.
used “new” code.
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 |
ppmutexOpenSSL = (CCriticalSection **) ::OPENSSL_malloc(::CRYPTO_num_locks() * sizeof(CCriticalSection *)); if(! ppmutexOpenSSL) { throw std::runtime_error("CInit OPENSSL_malloc allocate failure."); } for (int i = 0; i < ::CRYPTO_num_locks(); ++i) { ppmutexOpenSSL[i] = new CCriticalSection(); } ::CRYPTO_set_locking_callback(locking_callback); #ifdef WIN32 ::RAND_screen(); ::RAND_poll(); #endif // // Seed random number generator with performance counter // seed::RandAddSeed(); // // We use OpenSSL. // // // Shutdown OpenSSL library multithreading support // ::CRYPTO_set_locking_callback(NULL); for (int i = 0; i < ::CRYPTO_num_locks(); ++i) { delete ppmutexOpenSSL[i]; } ::OPENSSL_free(ppmutexOpenSSL); |
used “placement new” code.
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 |
pmutexOpenSSL = (CCriticalSection *) ::OPENSSL_malloc(::CRYPTO_num_locks() * sizeof(CCriticalSection)); if(! pmutexOpenSSL) { throw std::runtime_error("CInit OPENSSL_malloc allocate failure."); } for (int i=0; i < ::CRYPTO_num_locks(); ++i) { new(pmutexOpenSSL + i) CCriticalSection; } ::CRYPTO_set_locking_callback(locking_callback); #ifdef WIN32 ::RAND_screen(); ::RAND_poll(); #endif // // Seed random number generator with performance counter // seed::RandAddSeed(); // // We use OpenSSL. // // // Shutdown OpenSSL library multithreading support // ::CRYPTO_set_locking_callback(NULL); for (int i=0; i < ::CRYPTO_num_locks(); ++i) { (pmutexOpenSSL + i)->~CCriticalSection(); } ::OPENSSL_free(pmutexOpenSSL); |