[asterisk-scf-commits] asterisk-scf/integration/ice-util-cpp.git branch "sip-registrar" created.
Commits to the Asterisk SCF project code repositories
asterisk-scf-commits at lists.digium.com
Tue Jul 5 11:05:36 CDT 2011
branch "sip-registrar" has been created
at bfb569c7cde644bcd388f174536410bc7d4dbbcf (commit)
- Log -----------------------------------------------------------------
commit bfb569c7cde644bcd388f174536410bc7d4dbbcf
Author: Mark Michelson <mmichelson at digium.com>
Date: Tue Jul 5 11:05:14 2011 -0500
Add a thread hook to the default queue listener.
This was necessary due to its usage in the SIP component, plus it may
be a useful thing to have other places.
diff --git a/include/AsteriskSCF/WorkQueue/DefaultQueueListener.h b/include/AsteriskSCF/WorkQueue/DefaultQueueListener.h
index 06cc601..37df9ea 100644
--- a/include/AsteriskSCF/WorkQueue/DefaultQueueListener.h
+++ b/include/AsteriskSCF/WorkQueue/DefaultQueueListener.h
@@ -15,6 +15,8 @@
*/
#pragma once
+#include <Ice/Ice.h>
+
#include <boost/shared_ptr.hpp>
#include <AsteriskSCF/System/WorkQueue/WorkQueueIf.h>
@@ -43,7 +45,7 @@ class DefaultQueueListenerPriv;
class ASTSCF_DLL_EXPORT DefaultQueueListener : public AsteriskSCF::System::WorkQueue::V1::QueueListener
{
public:
- DefaultQueueListener(const AsteriskSCF::System::WorkQueue::V1::QueueBasePtr& queue);
+ DefaultQueueListener(const AsteriskSCF::System::WorkQueue::V1::QueueBasePtr& queue, const Ice::ThreadNotificationPtr& threadHook);
~DefaultQueueListener();
void workAdded(const AsteriskSCF::System::WorkQueue::V1::QueueBasePtr&, Ice::Long numNewWork, bool wasEmpty);
diff --git a/src/ThreadPool/ThreadPool.cpp b/src/ThreadPool/ThreadPool.cpp
index 6791084..44ce0df 100644
--- a/src/ThreadPool/ThreadPool.cpp
+++ b/src/ThreadPool/ThreadPool.cpp
@@ -41,7 +41,7 @@ public:
ThreadPool(const PoolListenerPtr& listener, const QueuePtr& queue)
: mControlQueue(new AsteriskSCF::WorkQueue::WorkQueue), mListener(listener), mQueue(queue), mShuttingDown(false)
{
- mControlQueue->setListener(new AsteriskSCF::WorkQueue::DefaultQueueListener(mControlQueue));
+ mControlQueue->setListener(new AsteriskSCF::WorkQueue::DefaultQueueListener(mControlQueue, 0));
ThreadQueueListenerPtr tqListener;
ThreadQueueListenerFactory factory;
tqListener = factory.createThreadQueueListener(this);
diff --git a/src/WorkQueue/DefaultQueueListener.cpp b/src/WorkQueue/DefaultQueueListener.cpp
index f191c17..4d46860 100644
--- a/src/WorkQueue/DefaultQueueListener.cpp
+++ b/src/WorkQueue/DefaultQueueListener.cpp
@@ -27,9 +27,9 @@ using namespace AsteriskSCF::System::WorkQueue::V1;
class DefaultQueueListenerPriv
{
public:
- DefaultQueueListenerPriv(const QueueBasePtr& queue)
+ DefaultQueueListenerPriv(const QueueBasePtr& queue, const Ice::ThreadNotificationPtr& threadHook)
: mWakeUp(false), mDead(false), mQueue(queue),
- mIsShutdown(false),
+ mIsShutdown(false), mThreadHook(threadHook),
mThread(boost::bind(&DefaultQueueListenerPriv::run, this)) { }
bool idle()
@@ -53,6 +53,10 @@ public:
* an infinite loop.
*/
bool localDead = false;
+ if (mThreadHook != 0)
+ {
+ mThreadHook->start();
+ }
while (!localDead)
{
try
@@ -68,6 +72,10 @@ public:
localDead = idle();
}
}
+ if (mThreadHook != 0)
+ {
+ mThreadHook->stop();
+ }
}
void setDead(bool dead)
@@ -84,11 +92,12 @@ public:
boost::mutex mLock;
boost::condition_variable mCond;
bool mIsShutdown;
+ Ice::ThreadNotificationPtr mThreadHook;
boost::thread mThread;
};
-DefaultQueueListener::DefaultQueueListener(const QueueBasePtr& queue)
- : mPriv(new DefaultQueueListenerPriv(queue)) { }
+DefaultQueueListener::DefaultQueueListener(const QueueBasePtr& queue, const Ice::ThreadNotificationPtr& threadHook)
+ : mPriv(new DefaultQueueListenerPriv(queue, threadHook)) { }
DefaultQueueListener::~DefaultQueueListener()
{
diff --git a/test/WorkQueue/TestWorkQueue.cpp b/test/WorkQueue/TestWorkQueue.cpp
index 50a0f9b..a2b6bb3 100644
--- a/test/WorkQueue/TestWorkQueue.cpp
+++ b/test/WorkQueue/TestWorkQueue.cpp
@@ -419,7 +419,7 @@ void waitForTaskCompletion(NotifyTaskPtr& task)
BOOST_AUTO_TEST_CASE(defaultListener)
{
QueuePtr queue(new WorkQueue());
- DefaultQueueListenerPtr listener(new DefaultQueueListener(queue));
+ DefaultQueueListenerPtr listener(new DefaultQueueListener(queue, 0));
NotifyTaskPtr work1(new NotifyTask);
NotifyTaskPtr work2(new NotifyTask);
NotifyTaskPtr work3(new NotifyTask);
-----------------------------------------------------------------------
--
asterisk-scf/integration/ice-util-cpp.git
More information about the asterisk-scf-commits
mailing list