diff options
| author | Andrew Stitcher <astitcher@apache.org> | 2009-12-07 15:42:14 +0000 |
|---|---|---|
| committer | Andrew Stitcher <astitcher@apache.org> | 2009-12-07 15:42:14 +0000 |
| commit | 7bbd0fdd577b167127633a7b52fe7ea487b1f267 (patch) | |
| tree | 5752af0626dad35879b91c96d09d802595f779d8 /cpp/src/qpid/sys/DeletionManager.h | |
| parent | 6a667d2a64bb124c585ef165821dfd60e3f5de04 (diff) | |
| download | qpid-python-7bbd0fdd577b167127633a7b52fe7ea487b1f267.tar.gz | |
QPID-2214: Opening and closing client connections causes memory use to grow unboundedly
- Clean up the DeletionManager state for each thread when the thread exits
git-svn-id: https://svn.apache.org/repos/asf/qpid/trunk/qpid@887956 13f79535-47bb-0310-9956-ffa450edef68
Diffstat (limited to 'cpp/src/qpid/sys/DeletionManager.h')
| -rw-r--r-- | cpp/src/qpid/sys/DeletionManager.h | 40 |
1 files changed, 34 insertions, 6 deletions
diff --git a/cpp/src/qpid/sys/DeletionManager.h b/cpp/src/qpid/sys/DeletionManager.h index 43154eb98e..5d8428966e 100644 --- a/cpp/src/qpid/sys/DeletionManager.h +++ b/cpp/src/qpid/sys/DeletionManager.h @@ -54,6 +54,8 @@ struct deleter template <typename H> class DeletionManager { + struct ThreadStatus; + public: // Mark every thread as using the handle - it will be deleted // below after every thread marks the handle as unused @@ -65,6 +67,28 @@ public: // handles get deleted here when no one else // is using them either static void markAllUnusedInThisThread() { + ThreadStatus* threadStatus = getThreadStatus(); + ScopedLock<Mutex> l(threadStatus->lock); + + // The actual deletions will happen here when all the shared_ptr + // ref counts hit 0 (that is when every thread marks the handle unused) + threadStatus->handles.clear(); + } + + static void destroyThreadState() { + ThreadStatus* threadStatus = getThreadStatus(); + { + ScopedLock<Mutex> l(threadStatus->lock); + + allThreadsStatuses.delThreadStatus(threadStatus); + } + delete threadStatus; + threadStatus = 0; + } + +private: + + static ThreadStatus*& getThreadStatus() { static __thread ThreadStatus* threadStatus = 0; // Thread local vars can't be dynamically constructed so we need @@ -75,14 +99,9 @@ public: allThreadsStatuses.addThreadStatus(threadStatus); } - ScopedLock<Mutex> l(threadStatus->lock); - - // The actual deletions will happen here when all the shared_ptr - // ref counts hit 0 (that is when every thread marks the handle unused) - threadStatus->handles.clear(); + return threadStatus; } -private: typedef boost::shared_ptr<H> shared_ptr; // In theory we know that we never need more handles than the number of @@ -125,6 +144,15 @@ private: statuses.push_back(t); } + void delThreadStatus(ThreadStatus* t) { + ScopedLock<Mutex> l(lock); + typename std::vector<ThreadStatus*>::iterator it = + std::find(statuses.begin(),statuses.end(), t); + if (it != statuses.end()) { + statuses.erase(it); + } + } + void addHandle(shared_ptr h) { ScopedLock<Mutex> l(lock); std::for_each(statuses.begin(), statuses.end(), handleAdder(h)); |
