From cb3c17573d095619493e6d25881a6a10b8804ea1 Mon Sep 17 00:00:00 2001 From: lotodore Date: Fri, 2 Mar 2007 00:34:50 +0000 Subject: [PATCH] That thread_specific_ptr was rubbish... --- src/core/win32/rand.cpp | 71 ++++++++++++++++++++--------------------- 1 file changed, 34 insertions(+), 37 deletions(-) diff --git a/src/core/win32/rand.cpp b/src/core/win32/rand.cpp index ec9d2fdb..4468f902 100644 --- a/src/core/win32/rand.cpp +++ b/src/core/win32/rand.cpp @@ -16,21 +16,20 @@ * Free Software Foundation, Inc., * * 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. * ***************************************************************************/ -#ifndef _WIN32 +#ifndef _WIN32 #error This source code is Win32 only. -#endif - -#include -#include +#endif -#include -#include - -class CryptData -{ -public: - CryptData() - { +#include +#include + +#include + +class CryptData +{ +public: + CryptData() + { if (!::CryptAcquireContext( &cryptProvider, NULL, @@ -40,27 +39,25 @@ public: { cryptProvider = 0; } - } - ~CryptData() - { - if (cryptProvider) CryptReleaseContext(cryptProvider, 0); - } - - HCRYPTPROV cryptProvider; -}; - -void -RandomBytes(unsigned char *buf, unsigned size) -{ - static boost::thread_specific_ptr m_cryptData; - - if (!m_cryptData.get()) - m_cryptData.reset(new CryptData); - - HCRYPTPROV provider = m_cryptData.get()->cryptProvider; - - if (provider) - ::CryptGenRandom(provider, size, buf); -} - - + } + ~CryptData() + { + if (cryptProvider) + CryptReleaseContext(cryptProvider, 0); + } + + HCRYPTPROV cryptProvider; +}; + +static CryptData g_cryptData; + +void +RandomBytes(unsigned char *buf, unsigned size) +{ + HCRYPTPROV provider = g_cryptData.cryptProvider; + + if (provider) + ::CryptGenRandom(provider, size, buf); +} + +