6 #ifndef CRYPTOPP_IMPORTS 8 #if !defined(NO_OS_DEPENDENCE) && defined(THREADS_AVAILABLE) 14 #define WIN32_LEAN_AND_MEAN 18 #if CRYPTOPP_GCC_DIAGNOSTIC_AVAILABLE 19 # pragma GCC diagnostic ignored "-Wc++11-compat" 24 ThreadLocalStorage::Err::Err(
const std::string& operation,
int error)
25 :
OS_Error(OTHER_ERROR,
"ThreadLocalStorage: " + operation +
" operation failed with error 0x" +
IntToString(error, 16), operation, error)
31 ThreadLocalStorage::ThreadLocalStorage()
36 if (m_index == TLS_OUT_OF_INDEXES)
37 throw Err(
"TlsAlloc", GetLastError());
40 int error = pthread_key_create(&m_index, NULLPTR);
43 throw Err(
"pthread_key_create", error);
47 ThreadLocalStorage::~ThreadLocalStorage() CRYPTOPP_THROW
49 #if defined(CRYPTOPP_CXX17_EXCEPTIONS) 50 if (std::uncaught_exceptions() == 0)
51 #elif defined(CRYPTOPP_UNCAUGHT_EXCEPTION_AVAILABLE) 52 if (std::uncaught_exception() ==
false)
58 int rc = TlsFree(m_index);
61 throw Err(
"TlsFree", GetLastError());
65 int error = pthread_key_delete(m_index);
68 throw Err(
"pthread_key_delete", error);
71 #if !defined(CRYPTOPP_CXX17_EXCEPTIONS) && !defined(CRYPTOPP_UNCAUGHT_EXCEPTION_AVAILABLE) 78 void ThreadLocalStorage::SetValue(
void *value)
81 if (!TlsSetValue(m_index, value))
82 throw Err(
"TlsSetValue", GetLastError());
84 int error = pthread_setspecific(m_index, value);
86 throw Err(
"pthread_key_getspecific", error);
90 void *ThreadLocalStorage::GetValue()
const 93 void *result = TlsGetValue(m_index);
94 const DWORD dwRet = GetLastError();
97 if (!result && dwRet != NO_ERROR)
98 throw Err(
"TlsGetValue", dwRet);
102 void *result = pthread_getspecific(m_index);
109 #endif // THREADS_AVAILABLE 110 #endif // CRYPTOPP_IMPORTS Base class for all exceptions thrown by the library.
The operating system reported an error.
Library configuration file.
#define CRYPTOPP_ASSERT(exp)
Debugging and diagnostic assertion.
std::string IntToString(T value, unsigned int base=10)
Converts a value to a string.
Crypto++ library namespace.