diff options
author | Kirill Volinsky <mataes2007@gmail.com> | 2012-07-20 16:21:49 +0000 |
---|---|---|
committer | Kirill Volinsky <mataes2007@gmail.com> | 2012-07-20 16:21:49 +0000 |
commit | f424a18112032cf61d2871a6b91a5af607c171ae (patch) | |
tree | 88fedc4e28941ceecda7026f0b06eba6271f91d5 /plugins/CryptoPP/crypto/src/trdlocal.cpp | |
parent | bfe1bd0fc087be44c70904aee0fe4276643d206d (diff) |
CryptoPP:
changed folder structure
git-svn-id: http://svn.miranda-ng.org/main/trunk@1083 1316c22d-e87f-b044-9b9b-93d7a3e3ba9c
Diffstat (limited to 'plugins/CryptoPP/crypto/src/trdlocal.cpp')
-rw-r--r-- | plugins/CryptoPP/crypto/src/trdlocal.cpp | 73 |
1 files changed, 73 insertions, 0 deletions
diff --git a/plugins/CryptoPP/crypto/src/trdlocal.cpp b/plugins/CryptoPP/crypto/src/trdlocal.cpp new file mode 100644 index 0000000000..6cf1799d06 --- /dev/null +++ b/plugins/CryptoPP/crypto/src/trdlocal.cpp @@ -0,0 +1,73 @@ +// trdlocal.cpp - written and placed in the public domain by Wei Dai
+
+#include "pch.h"
+
+#ifndef CRYPTOPP_IMPORTS
+#ifdef THREADS_AVAILABLE
+
+#include "trdlocal.h"
+
+#ifdef HAS_WINTHREADS
+#include <windows.h>
+#endif
+
+NAMESPACE_BEGIN(CryptoPP)
+
+ThreadLocalStorage::Err::Err(const std::string& operation, int error)
+ : OS_Error(OTHER_ERROR, "ThreadLocalStorage: " + operation + " operation failed with error 0x" + IntToString(error, 16), operation, error)
+{
+}
+
+ThreadLocalStorage::ThreadLocalStorage()
+{
+#ifdef HAS_WINTHREADS
+ m_index = TlsAlloc();
+ if (m_index == TLS_OUT_OF_INDEXES)
+ throw Err("TlsAlloc", GetLastError());
+#else
+ int error = pthread_key_create(&m_index, NULL);
+ if (error)
+ throw Err("pthread_key_create", error);
+#endif
+}
+
+ThreadLocalStorage::~ThreadLocalStorage()
+{
+#ifdef HAS_WINTHREADS
+ if (!TlsFree(m_index))
+ throw Err("TlsFree", GetLastError());
+#else
+ int error = pthread_key_delete(m_index);
+ if (error)
+ throw Err("pthread_key_delete", error);
+#endif
+}
+
+void ThreadLocalStorage::SetValue(void *value)
+{
+#ifdef HAS_WINTHREADS
+ if (!TlsSetValue(m_index, value))
+ throw Err("TlsSetValue", GetLastError());
+#else
+ int error = pthread_setspecific(m_index, value);
+ if (error)
+ throw Err("pthread_key_getspecific", error);
+#endif
+}
+
+void *ThreadLocalStorage::GetValue() const
+{
+#ifdef HAS_WINTHREADS
+ void *result = TlsGetValue(m_index);
+ if (!result && GetLastError() != NO_ERROR)
+ throw Err("TlsGetValue", GetLastError());
+#else
+ void *result = pthread_getspecific(m_index);
+#endif
+ return result;
+}
+
+NAMESPACE_END
+
+#endif // #ifdef THREADS_AVAILABLE
+#endif
|