[asterisk-scf-commits] asterisk-scf/integration/ice-util-cpp.git branch "pjlib-thread-hook" updated.
Commits to the Asterisk SCF project code repositories
asterisk-scf-commits at lists.digium.com
Thu Sep 29 06:40:11 CDT 2011
branch "pjlib-thread-hook" has been updated
via 595512ead47bdaa327dcfbdd5a94ae08470417c6 (commit)
from 139ce5a78d1e73772e8b54ca4b73f619a64ee247 (commit)
Summary of changes:
include/AsteriskSCF/PJLib/ThreadHook.h | 9 +++++++--
src/PJLib/ThreadHook.cpp | 7 ++++---
2 files changed, 11 insertions(+), 5 deletions(-)
- Log -----------------------------------------------------------------
commit 595512ead47bdaa327dcfbdd5a94ae08470417c6
Author: Kevin P. Fleming <kpfleming at digium.com>
Date: Thu Sep 29 06:39:25 2011 -0500
Trying again... using an instance member variable (mutex) to protect access to
a static member variable was clearly not a good idea.
diff --git a/include/AsteriskSCF/PJLib/ThreadHook.h b/include/AsteriskSCF/PJLib/ThreadHook.h
index 6300fd7..dbae437 100644
--- a/include/AsteriskSCF/PJLib/ThreadHook.h
+++ b/include/AsteriskSCF/PJLib/ThreadHook.h
@@ -124,15 +124,20 @@ private:
std::map<pj_thread_t*, ThreadDescWrapperPtr> mpjThreads;
/**
+ * Mutex to protect the map
+ */
+ boost::mutex mMapLock;
+
+ /**
* A flag to indicate whether the PJ libraries have already been initialized by an instance
* of this class.
*/
static bool mpjInitialized;
/**
- * Mutex to protect the map and the flag
+ * Mutex to protect the flag
*/
- boost::mutex mLock;
+ static boost::mutex mInitLock;
/**
* A string indicating the group that threads being tracked by this hook belong to.
diff --git a/src/PJLib/ThreadHook.cpp b/src/PJLib/ThreadHook.cpp
index 8d8443b..93a7bab 100644
--- a/src/PJLib/ThreadHook.cpp
+++ b/src/PJLib/ThreadHook.cpp
@@ -25,13 +25,14 @@ namespace PJLib
{
bool ThreadHook::mpjInitialized;
+boost::mutex ThreadHook::mInitLock;
/**
* Constructor which initializes the PJSIP libraries.
*/
ThreadHook::ThreadHook(const std::string& threadGroup) : mThreadGroup(threadGroup)
{
- boost::lock_guard<boost::mutex> lock(mLock);
+ boost::lock_guard<boost::mutex> lock(mInitLock);
if(!mpjInitialized)
{
@@ -67,7 +68,7 @@ void ThreadHook::start()
}
else
{
- boost::lock_guard<boost::mutex> lock(mLock);
+ boost::lock_guard<boost::mutex> lock(mMapLock);
mpjThreads.insert(std::make_pair(thread, wrapper));
}
}
@@ -79,7 +80,7 @@ void ThreadHook::stop()
{
if (pj_thread_is_registered())
{
- boost::lock_guard<boost::mutex> lock(mLock);
+ boost::lock_guard<boost::mutex> lock(mMapLock);
mpjThreads.erase(pj_thread_this());
}
}
-----------------------------------------------------------------------
--
asterisk-scf/integration/ice-util-cpp.git
More information about the asterisk-scf-commits
mailing list