[asterisk-scf-commits] asterisk-scf/release/ice-util-cpp.git branch "master" updated.
Commits to the Asterisk SCF project code repositories
asterisk-scf-commits at lists.digium.com
Wed Jul 6 15:37:52 CDT 2011
branch "master" has been updated
via 0de3a6da08326394ca81228ee1c0ae770f78dbcb (commit)
via 46735aa3466327f819e9da924274338894a6d75c (commit)
from 94a22d0051ee42490b47c41cc81b0f0e61cf36ec (commit)
Summary of changes:
.../AsteriskSCF/WorkQueue/DefaultQueueListener.h | 4 ++-
src/ThreadPool/ThreadPool.cpp | 2 +-
src/WorkQueue/DefaultQueueListener.cpp | 17 ++++++++--
test/WorkQueue/TestWorkQueue.cpp | 30 +++++++++++++++++++-
4 files changed, 46 insertions(+), 7 deletions(-)
- Log -----------------------------------------------------------------
commit 0de3a6da08326394ca81228ee1c0ae770f78dbcb
Author: Mark Michelson <mmichelson at digium.com>
Date: Wed Jul 6 15:25:26 2011 -0500
Add threadhook testing to the DefaultQueueListener test as suggested in CR-ASTSCF-117
diff --git a/test/WorkQueue/TestWorkQueue.cpp b/test/WorkQueue/TestWorkQueue.cpp
index a2b6bb3..4bab4fa 100644
--- a/test/WorkQueue/TestWorkQueue.cpp
+++ b/test/WorkQueue/TestWorkQueue.cpp
@@ -75,6 +75,26 @@ public:
typedef IceUtil::Handle<Task> TaskPtr;
+class ThreadHook : public Ice::ThreadNotification
+{
+public:
+ ThreadHook()
+ : mStarted(false), mStopped(false) { }
+ void start()
+ {
+ mStarted = true;
+ }
+ void stop()
+ {
+ mStopped = true;
+ }
+
+ bool mStarted;
+ bool mStopped;
+};
+
+typedef IceUtil::Handle<ThreadHook> ThreadHookPtr;
+
/**
* Like a Task, but it has the capability
* of notifying a waiting thread when the
@@ -419,13 +439,17 @@ void waitForTaskCompletion(NotifyTaskPtr& task)
BOOST_AUTO_TEST_CASE(defaultListener)
{
QueuePtr queue(new WorkQueue());
- DefaultQueueListenerPtr listener(new DefaultQueueListener(queue, 0));
+ ThreadHookPtr tHook(new ThreadHook());
+ DefaultQueueListenerPtr listener(new DefaultQueueListener(queue, tHook));
NotifyTaskPtr work1(new NotifyTask);
NotifyTaskPtr work2(new NotifyTask);
NotifyTaskPtr work3(new NotifyTask);
NotifyTaskPtr work4(new NotifyTask);
WorkSeq works;
+ BOOST_CHECK(tHook->mStarted == true);
+ BOOST_CHECK(tHook->mStopped == false);
+
queue->setListener(listener);
works.push_back(work1);
@@ -451,6 +475,10 @@ BOOST_AUTO_TEST_CASE(defaultListener)
waitForTaskCompletion(work5);
BOOST_CHECK(work5->taskExecuted == true);
+
+ queue->shutdown();
+
+ BOOST_CHECK(tHook->mStopped == true);
}
BOOST_AUTO_TEST_SUITE_END()
commit 46735aa3466327f819e9da924274338894a6d75c
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/release/ice-util-cpp.git
More information about the asterisk-scf-commits
mailing list