You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@activemq.apache.org by ta...@apache.org on 2015/07/10 21:07:37 UTC

activemq-cpp git commit: https://issues.apache.org/jira/browse/AMQCPP-564

Repository: activemq-cpp
Updated Branches:
  refs/heads/master 7853c44e7 -> e81bfc25b


https://issues.apache.org/jira/browse/AMQCPP-564

Apply patch allowing user to purge OS link thread resources. 

Project: http://git-wip-us.apache.org/repos/asf/activemq-cpp/repo
Commit: http://git-wip-us.apache.org/repos/asf/activemq-cpp/commit/e81bfc25
Tree: http://git-wip-us.apache.org/repos/asf/activemq-cpp/tree/e81bfc25
Diff: http://git-wip-us.apache.org/repos/asf/activemq-cpp/diff/e81bfc25

Branch: refs/heads/master
Commit: e81bfc25b935e08d86610ae712b555be38610fc6
Parents: 7853c44
Author: Timothy Bish <ta...@gmail.com>
Authored: Fri Jul 10 15:07:25 2015 -0400
Committer: Timothy Bish <ta...@gmail.com>
Committed: Fri Jul 10 15:07:25 2015 -0400

----------------------------------------------------------------------
 .../internal/util/concurrent/Threading.cpp      | 41 ++++++++++++++++++++
 .../decaf/internal/util/concurrent/Threading.h  |  4 +-
 2 files changed, 44 insertions(+), 1 deletion(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/activemq-cpp/blob/e81bfc25/activemq-cpp/src/main/decaf/internal/util/concurrent/Threading.cpp
----------------------------------------------------------------------
diff --git a/activemq-cpp/src/main/decaf/internal/util/concurrent/Threading.cpp b/activemq-cpp/src/main/decaf/internal/util/concurrent/Threading.cpp
index 89359f4..53d6c81 100644
--- a/activemq-cpp/src/main/decaf/internal/util/concurrent/Threading.cpp
+++ b/activemq-cpp/src/main/decaf/internal/util/concurrent/Threading.cpp
@@ -1674,3 +1674,44 @@ void Threading::destoryThreadLocalSlot(int slot) {
     library->tlsSlots[slot] = NULL;
     PlatformThread::unlockMutex(library->tlsLock);
 }
+
+////////////////////////////////////////////////////////////////////////////////
+void Threading::releaseCurrentThreadHandle() {
+    ThreadHandle* self = (ThreadHandle*)PlatformThread::getTlsValue(library->selfKey);
+
+    if (self != NULL) {
+        detachFromCurrentThread(self);
+    }
+}
+
+////////////////////////////////////////////////////////////////////////////////
+void Threading::detachFromCurrentThread(ThreadHandle* self) {
+
+    PlatformThread::lockMutex(library->globalLock);
+
+    // Destroy given Foreign Thread Facade that was created during runtime.
+    std::vector<Thread*>::iterator iter = library->osThreads.begin();
+    bool isFound = false;
+    for (; iter != library->osThreads.end(); ++iter) {
+        if (self->parent == *iter) {
+            isFound = true;
+            break;
+        }
+    }
+
+    if (isFound) {
+        PlatformThread::setTlsValue(library->threadKey, NULL);
+        PlatformThread::setTlsValue(library->selfKey, NULL);
+
+        // Ensure all of this thread's local values are purged.
+        threadExitTlsCleanup(self);
+
+        // Destroy OS thread including self thread handle.
+        delete *iter;
+
+        // Remove thread form the global list.
+        library->osThreads.erase(iter);
+    }
+
+    PlatformThread::unlockMutex(library->globalLock);
+}

http://git-wip-us.apache.org/repos/asf/activemq-cpp/blob/e81bfc25/activemq-cpp/src/main/decaf/internal/util/concurrent/Threading.h
----------------------------------------------------------------------
diff --git a/activemq-cpp/src/main/decaf/internal/util/concurrent/Threading.h b/activemq-cpp/src/main/decaf/internal/util/concurrent/Threading.h
index 2b46f44..466e631 100644
--- a/activemq-cpp/src/main/decaf/internal/util/concurrent/Threading.h
+++ b/activemq-cpp/src/main/decaf/internal/util/concurrent/Threading.h
@@ -333,11 +333,13 @@ namespace concurrent {
         static void setThreadLocalValue(int slot, void* value);
 
         static void destoryThreadLocalSlot(int slot);
+	
+        static void releaseCurrentThreadHandle();
 
     private:
 
         static ThreadHandle* attachToCurrentThread();
-
+        static void detachFromCurrentThread(ThreadHandle* thread);
         static void monitorEnterUsingThreadId(MonitorHandle* monitor, ThreadHandle* thread);
         static bool monitorTryEnterUsingThreadId(MonitorHandle* monitor, ThreadHandle* thread);
         static void monitorExitUsingThreadId(MonitorHandle* monitor, ThreadHandle* thread);