Author: tabish
Date: Tue Sep 22 13:55:38 2009
New Revision: 817665
URL: http://svn.apache.org/viewvc?rev=817665&view=rev
Log:
Add TLS bits for Windows into the Thread class.
Modified:
activemq/activemq-cpp/trunk/activemq-cpp/src/main/decaf/lang/Thread.cpp
Modified:
activemq/activemq-cpp/trunk/activemq-cpp/src/main/decaf/lang/Thread.cpp
URL:
http://svn.apache.org/viewvc/activemq/activemq-cpp/trunk/activemq-cpp/src/main/decaf/lang/Thread.cpp?rev=817665&r1=817664&r2=817665&view=diff
==============================================================================
--- activemq/activemq-cpp/trunk/activemq-cpp/src/main/decaf/lang/Thread.cpp
(original)
+++ activemq/activemq-cpp/trunk/activemq-cpp/src/main/decaf/lang/Thread.cpp Tue
Sep 22 13:55:38 2009
@@ -193,13 +193,17 @@
}
#else
- Thread* currentThread;
+ DWORD currentThreadKey;
unsigned int __stdcall threadWorker( void* arg ) {
ThreadProperties* properties = (ThreadProperties*)arg;
+ ::TlsSetValue( currentThreadKey, (void*)properties->parent );
+
ThreadProperties::runCallback( properties );
+ ::TlsSetValue( currentThreadKey, NULL );
+
#ifndef _WIN32_WCE
_endthreadex( 0 );
#else
@@ -234,6 +238,14 @@
pthread_key_create( ¤tThreadKey, NULL );
pthread_setspecific( currentThreadKey, mainThread );
+ #else
+
+ mainThread->properties->handle = getCurrentThread();
+
+ // Create the key used to store the Current Thread data
+ currentThreadKey = ::TlsAlloc();
+ ::TlsSetValue( currentThreadKey, mainThread );
+
#endif
}
@@ -250,6 +262,15 @@
// Destroy the current Thread key now, no longer needed.
pthread_key_delete( currentThreadKey );
+ #else
+
+ Thread* mainThread = (Thread*) ::TlsGetValue( currentThreadKey );
+
+ delete mainThread;
+
+ // Destroy our TLS resources before we shutdown.
+ ::TlsFree( currentThreadKey );
+
#endif
}
@@ -555,17 +576,22 @@
////////////////////////////////////////////////////////////////////////////////
Thread* Thread::currentThread() {
+ void* result = NULL;
+
#ifdef HAVE_PTHREAD_H
- // Grab the Thread Local copy
- void* result = pthread_getspecific( currentThreadKey );
- if( result == NULL ) {
- throw RuntimeException(
- __FILE__, __LINE__, "Failed to find the Current Thread pointer
in the TLS." );
- }
+ result = pthread_getspecific( currentThreadKey );
- return (Thread*)result;
#else
- return NULL;
+
+ result = ::TlsGetValue( currentThreadKey );
+
#endif
+
+ if( result == NULL ) {
+ throw RuntimeException(
+ __FILE__, __LINE__, "Failed to find the Current Thread pointer in
the TLS." );
+ }
+
+ return (Thread*)result;
}