[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
Fri Jun 24 16:29:26 CDT 2011


branch "master" has been updated
       via  2efd9ccf97166aa7b04d1e801ff576aab8e42e03 (commit)
       via  6deb16a94cc65923dfe812f839a153b8f38423ae (commit)
       via  42ebe7e6ec3a127ad6593cc40a8d07eba2e6d95c (commit)
       via  6da01131aef4cb6b009514adbd3acfefcbcfd5a7 (commit)
       via  d813bbcb95b2151ea23404268e18d2fcb891fd20 (commit)
       via  eb3e3d33fd4fbdb5e734bdac29572f9e2aab8c17 (commit)
      from  77fbd062c219503ed3735918d4c2346a5b9a9d4b (commit)

Summary of changes:
 .../AsteriskSCF/WorkQueue/DefaultQueueListener.h   |   11 +-
 .../AsteriskSCF/WorkQueue/SuspendableWorkQueue.h   |    1 +
 include/AsteriskSCF/WorkQueue/WorkQueue.h          |    1 +
 src/ThreadPool/ThreadPool.cpp                      |   12 ++-
 src/WorkQueue/DefaultQueueListener.cpp             |   47 +++++--
 src/WorkQueue/SuspendableWorkQueue.cpp             |   46 +++++--
 src/WorkQueue/WorkQueue.cpp                        |   40 +++++-
 test/ThreadPool/TestThreadPool.cpp                 |   11 ++-
 test/WorkQueue/TestSuspendableWorkQueue.cpp        |  139 +++++++++++++++++++-
 test/WorkQueue/TestWorkQueue.cpp                   |  129 ++++++++++++++++++-
 10 files changed, 392 insertions(+), 45 deletions(-)


- Log -----------------------------------------------------------------
commit 2efd9ccf97166aa7b04d1e801ff576aab8e42e03
Merge: 77fbd06 6deb16a
Author: Mark Michelson <mmichelson at digium.com>
Date:   Fri Jun 24 16:28:07 2011 -0500

    Merge branch 'queue-shutdown'

diff --cc include/AsteriskSCF/WorkQueue/DefaultQueueListener.h
index 5d01d78,6169552..06cc601
--- a/include/AsteriskSCF/WorkQueue/DefaultQueueListener.h
+++ b/include/AsteriskSCF/WorkQueue/DefaultQueueListener.h
@@@ -40,14 -40,17 +40,17 @@@ class DefaultQueueListenerPriv
   * as a matter of convenience.
   */
  
 -class ASTERISK_SCF_ICEBOX_EXPORT DefaultQueueListener : public AsteriskSCF::System::WorkQueue::V1::QueueListener
 +class ASTSCF_DLL_EXPORT DefaultQueueListener : public AsteriskSCF::System::WorkQueue::V1::QueueListener
  {
  public:
-     DefaultQueueListener(const AsteriskSCF::System::WorkQueue::V1::QueuePtr& queue);
+     DefaultQueueListener(const AsteriskSCF::System::WorkQueue::V1::QueueBasePtr& queue);
      ~DefaultQueueListener();
-     void workAdded(Ice::Long numNewWork, bool wasEmpty);
-     void workResumable();
-     void emptied();
+     
+     void workAdded(const AsteriskSCF::System::WorkQueue::V1::QueueBasePtr&, Ice::Long numNewWork, bool wasEmpty);
+     void workResumable(const AsteriskSCF::System::WorkQueue::V1::QueueBasePtr&);
+     void emptied(const AsteriskSCF::System::WorkQueue::V1::QueueBasePtr&);
+     void shuttingDown(const AsteriskSCF::System::WorkQueue::V1::QueueBasePtr&);
+ 
  private:
      boost::shared_ptr<DefaultQueueListenerPriv> mPriv;
  };

commit 6deb16a94cc65923dfe812f839a153b8f38423ae
Author: Mark Michelson <mmichelson at digium.com>
Date:   Fri Jun 24 16:21:08 2011 -0500

    Change from shutDown to shutdown.

diff --git a/include/AsteriskSCF/WorkQueue/SuspendableWorkQueue.h b/include/AsteriskSCF/WorkQueue/SuspendableWorkQueue.h
index 8c3ba09..1717ea1 100644
--- a/include/AsteriskSCF/WorkQueue/SuspendableWorkQueue.h
+++ b/include/AsteriskSCF/WorkQueue/SuspendableWorkQueue.h
@@ -41,7 +41,7 @@ public:
     bool executeWork();
     Ice::Long getSize();
     void setListener(const AsteriskSCF::System::WorkQueue::V1::QueueListenerPtr& listener);
-    void shutDown();
+    void shutdown();
 private:
     boost::shared_ptr<SuspendableWorkQueuePriv> mPriv;
 };
diff --git a/include/AsteriskSCF/WorkQueue/WorkQueue.h b/include/AsteriskSCF/WorkQueue/WorkQueue.h
index f7aee13..1357bd3 100644
--- a/include/AsteriskSCF/WorkQueue/WorkQueue.h
+++ b/include/AsteriskSCF/WorkQueue/WorkQueue.h
@@ -40,7 +40,7 @@ public:
     bool executeWork();
     Ice::Long getSize();
     void setListener(const AsteriskSCF::System::WorkQueue::V1::QueueListenerPtr& listener);
-    void shutDown();
+    void shutdown();
 private:
     boost::shared_ptr<WorkQueuePriv> mPriv;
 };
diff --git a/src/WorkQueue/SuspendableWorkQueue.cpp b/src/WorkQueue/SuspendableWorkQueue.cpp
index b5346d2..b4f53e1 100644
--- a/src/WorkQueue/SuspendableWorkQueue.cpp
+++ b/src/WorkQueue/SuspendableWorkQueue.cpp
@@ -384,7 +384,7 @@ void SuspendableWorkQueue::setListener(const QueueListenerPtr& listener)
     mPriv->mListener = listener;
 }
 
-void SuspendableWorkQueue::shutDown()
+void SuspendableWorkQueue::shutdown()
 {
     boost::unique_lock<boost::shared_mutex> lock(mPriv->mLock);
     mPriv->checkForShuttingDown();
diff --git a/src/WorkQueue/WorkQueue.cpp b/src/WorkQueue/WorkQueue.cpp
index fa50b5c..a4a9da0 100644
--- a/src/WorkQueue/WorkQueue.cpp
+++ b/src/WorkQueue/WorkQueue.cpp
@@ -185,7 +185,7 @@ void WorkQueue::setListener(const QueueListenerPtr& listener)
     mPriv->mListener = listener;
 }
 
-void WorkQueue::shutDown()
+void WorkQueue::shutdown()
 {
     boost::unique_lock<boost::shared_mutex> lock(mPriv->mLock);
     mPriv->checkForShuttingDown();
diff --git a/test/WorkQueue/TestSuspendableWorkQueue.cpp b/test/WorkQueue/TestSuspendableWorkQueue.cpp
index ab7f979..f469cfc 100644
--- a/test/WorkQueue/TestSuspendableWorkQueue.cpp
+++ b/test/WorkQueue/TestSuspendableWorkQueue.cpp
@@ -191,7 +191,7 @@ BOOST_AUTO_TEST_CASE(addWork)
     BOOST_CHECK(listener->addedEmptyNotice == true);
     BOOST_CHECK(queue->getSize() == 1);
 
-    queue->shutDown();
+    queue->shutdown();
 
     BOOST_CHECK(listener->shutdownNotice == true);
 }
@@ -213,17 +213,17 @@ BOOST_AUTO_TEST_CASE(addWorkSeq)
     BOOST_CHECK(listener->emptyNotice == false);
     BOOST_CHECK(queue->getSize() == 2);
 
-    queue->shutDown();
+    queue->shutdown();
 
     BOOST_CHECK(listener->shutdownNotice == true);
 }
 
-BOOST_AUTO_TEST_CASE(shutDownException)
+BOOST_AUTO_TEST_CASE(shutdownException)
 {
     TestListenerPtr listener(new TestListener);
     SuspendableQueuePtr queue(new SuspendableWorkQueue(listener));
 
-    queue->shutDown();
+    queue->shutdown();
 
     bool excepted;
     try
@@ -284,7 +284,7 @@ BOOST_AUTO_TEST_CASE(shutDownException)
 
     try
     {
-        queue->shutDown();
+        queue->shutdown();
     }
     catch (const ShuttingDown&)
     {
@@ -311,7 +311,7 @@ BOOST_AUTO_TEST_CASE(appendWork)
     BOOST_CHECK(listener->emptyNotice == false);
     BOOST_CHECK(queue->getSize() == 2);
 
-    queue->shutDown();
+    queue->shutdown();
 
     BOOST_CHECK(listener->shutdownNotice == true);
 }
@@ -338,7 +338,7 @@ BOOST_AUTO_TEST_CASE(cancelWork)
     BOOST_CHECK(listener->emptyNotice == true);
     BOOST_CHECK(queue->getSize() == 0);
 
-    queue->shutDown();
+    queue->shutdown();
 
     BOOST_CHECK(listener->shutdownNotice == true);
 }
@@ -365,7 +365,7 @@ BOOST_AUTO_TEST_CASE(cancelNonExistent1)
     BOOST_CHECK(listener->emptyNotice == false);
     BOOST_CHECK(queue->getSize() == 0);
 
-    queue->shutDown();
+    queue->shutdown();
 
     BOOST_CHECK(listener->shutdownNotice == true);
 }
@@ -392,7 +392,7 @@ BOOST_AUTO_TEST_CASE(cancelNonExistent2)
     BOOST_CHECK(excepted == false);
     BOOST_CHECK(queue->getSize() == 1);
 
-    queue->shutDown();
+    queue->shutdown();
 
     BOOST_CHECK(listener->shutdownNotice == true);
 }
@@ -411,7 +411,7 @@ BOOST_AUTO_TEST_CASE(simpleWorkExecution)
     BOOST_CHECK(listener->emptyNotice == true);
     BOOST_CHECK(queue->getSize() == 0);
 
-    queue->shutDown();
+    queue->shutdown();
 
     BOOST_CHECK(listener->shutdownNotice == true);
 }
@@ -427,7 +427,7 @@ BOOST_AUTO_TEST_CASE(executeNonExistent)
     BOOST_CHECK(queue->getSize() == 0);
     BOOST_CHECK(listener->emptyNotice == false);
 
-    queue->shutDown();
+    queue->shutdown();
 
     BOOST_CHECK(listener->shutdownNotice == true);
 }
@@ -455,7 +455,7 @@ BOOST_AUTO_TEST_CASE(executionOrder1)
     BOOST_CHECK(listener->emptyNotice == true);
     BOOST_CHECK(queue->getSize() == 0);
 
-    queue->shutDown();
+    queue->shutdown();
 
     BOOST_CHECK(listener->shutdownNotice == true);
 }
@@ -507,7 +507,7 @@ BOOST_AUTO_TEST_CASE(executionOrder2)
     BOOST_CHECK(listener->emptyNotice == true);
     BOOST_CHECK(queue->getSize() == 0);
 
-    queue->shutDown();
+    queue->shutdown();
 
     BOOST_CHECK(listener->shutdownNotice == true);
 }
@@ -581,7 +581,7 @@ BOOST_AUTO_TEST_CASE(complexWork)
     BOOST_CHECK(work->currentState == ComplexTask::Task2Complete);
     BOOST_CHECK(listener->emptyNotice == true);
 
-    queue->shutDown();
+    queue->shutdown();
 
     BOOST_CHECK(listener->shutdownNotice == true);
 }
@@ -612,7 +612,7 @@ BOOST_AUTO_TEST_CASE(racyWork)
     BOOST_CHECK(queue->getSize() == 0);
     BOOST_CHECK(listener->emptyNotice == true);
 
-    queue->shutDown();
+    queue->shutdown();
 
     BOOST_CHECK(listener->shutdownNotice == true);
 }
diff --git a/test/WorkQueue/TestWorkQueue.cpp b/test/WorkQueue/TestWorkQueue.cpp
index 97ea1ad..50a0f9b 100644
--- a/test/WorkQueue/TestWorkQueue.cpp
+++ b/test/WorkQueue/TestWorkQueue.cpp
@@ -112,17 +112,17 @@ BOOST_AUTO_TEST_CASE(addWork)
     BOOST_CHECK(listener->tasksAdded == 1);
     BOOST_CHECK(queue->getSize() == 1);
 
-    queue->shutDown();
+    queue->shutdown();
 
     BOOST_CHECK(listener->shutdownNotice == true);
 }
 
-BOOST_AUTO_TEST_CASE(shutDownException)
+BOOST_AUTO_TEST_CASE(shutdownException)
 {
     TestListenerPtr listener(new TestListener);
     QueuePtr queue(new WorkQueue(listener));
 
-    queue->shutDown();
+    queue->shutdown();
 
     bool excepted;
     try
@@ -183,7 +183,7 @@ BOOST_AUTO_TEST_CASE(shutDownException)
 
     try
     {
-        queue->shutDown();
+        queue->shutdown();
     }
     catch (const ShuttingDown&)
     {
@@ -210,7 +210,7 @@ BOOST_AUTO_TEST_CASE(addWorkSeq)
     BOOST_CHECK(listener->tasksAdded == 2);
     BOOST_CHECK(queue->getSize() == 2);
 
-    queue->shutDown();
+    queue->shutdown();
 
     BOOST_CHECK(listener->shutdownNotice == true);
 }
@@ -233,7 +233,7 @@ BOOST_AUTO_TEST_CASE(appendWork)
     BOOST_CHECK(listener->tasksAdded == 1);
     BOOST_CHECK(queue->getSize() == 2);
 
-    queue->shutDown();
+    queue->shutdown();
 
     BOOST_CHECK(listener->shutdownNotice == true);
 }
@@ -251,7 +251,7 @@ BOOST_AUTO_TEST_CASE(cancelWork)
     BOOST_CHECK(listener->emptyNotice == true);
     BOOST_CHECK(queue->getSize() == 0);
 
-    queue->shutDown();
+    queue->shutdown();
 
     BOOST_CHECK(listener->shutdownNotice == true);
 }
@@ -269,7 +269,7 @@ BOOST_AUTO_TEST_CASE(cancelNonExistent1)
     BOOST_CHECK(listener->emptyNotice == false);
     BOOST_CHECK(queue->getSize() == 0);
 
-    queue->shutDown();
+    queue->shutdown();
 
     BOOST_CHECK(listener->shutdownNotice == true);
 }
@@ -287,7 +287,7 @@ BOOST_AUTO_TEST_CASE(cancelNonExistent2)
 
     BOOST_CHECK(queue->getSize() == 1);
 
-    queue->shutDown();
+    queue->shutdown();
 
     BOOST_CHECK(listener->shutdownNotice == true);
 }
@@ -306,7 +306,7 @@ BOOST_AUTO_TEST_CASE(workExecution)
     BOOST_CHECK(listener->emptyNotice == true);
     BOOST_CHECK(queue->getSize() == 0);
 
-    queue->shutDown();
+    queue->shutdown();
 
     BOOST_CHECK(listener->shutdownNotice == true);
 }
@@ -322,7 +322,7 @@ BOOST_AUTO_TEST_CASE(executeNonExistent)
     BOOST_CHECK(queue->getSize() == 0);
     BOOST_CHECK(listener->emptyNotice == false);
 
-    queue->shutDown();
+    queue->shutdown();
 
     BOOST_CHECK(listener->shutdownNotice == true);
 }
@@ -350,7 +350,7 @@ BOOST_AUTO_TEST_CASE(executionOrder1)
     BOOST_CHECK(listener->emptyNotice == true);
     BOOST_CHECK(queue->getSize() == 0);
 
-    queue->shutDown();
+    queue->shutdown();
 
     BOOST_CHECK(listener->shutdownNotice == true);
 }
@@ -402,7 +402,7 @@ BOOST_AUTO_TEST_CASE(executionOrder2)
     BOOST_CHECK(listener->emptyNotice == true);
     BOOST_CHECK(queue->getSize() == 0);
 
-    queue->shutDown();
+    queue->shutdown();
 
     BOOST_CHECK(listener->shutdownNotice == true);
 }

commit 42ebe7e6ec3a127ad6593cc40a8d07eba2e6d95c
Author: Mark Michelson <mmichelson at digium.com>
Date:   Fri Jun 24 16:14:07 2011 -0500

    Catch ShuttingDown exceptions by const reference.
    
    Suggested in CR-ASTSCF-98

diff --git a/test/WorkQueue/TestSuspendableWorkQueue.cpp b/test/WorkQueue/TestSuspendableWorkQueue.cpp
index 5cf376c..ab7f979 100644
--- a/test/WorkQueue/TestSuspendableWorkQueue.cpp
+++ b/test/WorkQueue/TestSuspendableWorkQueue.cpp
@@ -230,7 +230,7 @@ BOOST_AUTO_TEST_CASE(shutDownException)
     {
         queue->getSize();
     }
-    catch (ShuttingDown)
+    catch (const ShuttingDown&)
     {
         excepted = true;
     }
@@ -242,7 +242,7 @@ BOOST_AUTO_TEST_CASE(shutDownException)
     {
         queue->enqueueWork(work);
     }
-    catch (ShuttingDown)
+    catch (const ShuttingDown&)
     {
         excepted = true;
     }
@@ -253,7 +253,7 @@ BOOST_AUTO_TEST_CASE(shutDownException)
     {
         queue->executeWork();
     }
-    catch (ShuttingDown)
+    catch (const ShuttingDown&)
     {
         excepted = true;
     }
@@ -264,7 +264,7 @@ BOOST_AUTO_TEST_CASE(shutDownException)
     {
         queue->cancelWork(work);
     }
-    catch (ShuttingDown)
+    catch (const ShuttingDown&)
     {
         excepted = true;
     }
@@ -275,7 +275,7 @@ BOOST_AUTO_TEST_CASE(shutDownException)
     {
         queue->setListener(listener);
     }
-    catch (ShuttingDown)
+    catch (const ShuttingDown&)
     {
         excepted = true;
     }
@@ -286,7 +286,7 @@ BOOST_AUTO_TEST_CASE(shutDownException)
     {
         queue->shutDown();
     }
-    catch (ShuttingDown)
+    catch (const ShuttingDown&)
     {
         excepted = true;
     }
diff --git a/test/WorkQueue/TestWorkQueue.cpp b/test/WorkQueue/TestWorkQueue.cpp
index 79f357d..97ea1ad 100644
--- a/test/WorkQueue/TestWorkQueue.cpp
+++ b/test/WorkQueue/TestWorkQueue.cpp
@@ -129,7 +129,7 @@ BOOST_AUTO_TEST_CASE(shutDownException)
     {
         queue->getSize();
     }
-    catch (ShuttingDown)
+    catch (const ShuttingDown&)
     {
         excepted = true;
     }
@@ -141,7 +141,7 @@ BOOST_AUTO_TEST_CASE(shutDownException)
     {
         queue->enqueueWork(work);
     }
-    catch (ShuttingDown)
+    catch (const ShuttingDown&)
     {
         excepted = true;
     }
@@ -152,7 +152,7 @@ BOOST_AUTO_TEST_CASE(shutDownException)
     {
         queue->executeWork();
     }
-    catch (ShuttingDown)
+    catch (const ShuttingDown&)
     {
         excepted = true;
     }
@@ -163,7 +163,7 @@ BOOST_AUTO_TEST_CASE(shutDownException)
     {
         queue->cancelWork(work);
     }
-    catch (ShuttingDown)
+    catch (const ShuttingDown&)
     {
         excepted = true;
     }
@@ -174,7 +174,7 @@ BOOST_AUTO_TEST_CASE(shutDownException)
     {
         queue->setListener(listener);
     }
-    catch (ShuttingDown)
+    catch (const ShuttingDown&)
     {
         excepted = true;
     }
@@ -185,7 +185,7 @@ BOOST_AUTO_TEST_CASE(shutDownException)
     {
         queue->shutDown();
     }
-    catch (ShuttingDown)
+    catch (const ShuttingDown&)
     {
         excepted = true;
     }

commit 6da01131aef4cb6b009514adbd3acfefcbcfd5a7
Author: Mark Michelson <mmichelson at digium.com>
Date:   Mon Jun 6 16:48:55 2011 -0500

    Add appropriate changes based on changes to QueueListener

diff --git a/src/WorkQueue/DefaultQueueListener.cpp b/src/WorkQueue/DefaultQueueListener.cpp
index 82490b3..f191c17 100644
--- a/src/WorkQueue/DefaultQueueListener.cpp
+++ b/src/WorkQueue/DefaultQueueListener.cpp
@@ -90,6 +90,15 @@ public:
 DefaultQueueListener::DefaultQueueListener(const QueueBasePtr& queue)
     : mPriv(new DefaultQueueListenerPriv(queue)) { }
 
+DefaultQueueListener::~DefaultQueueListener()
+{
+    if (!mPriv->mIsShutdown)
+    {
+        mPriv->setDead(true);
+        mPriv->mThread.join();
+    }
+}
+
 void DefaultQueueListener::workAdded(const QueueBasePtr&, Ice::Long, bool wasEmpty)
 {
     if (wasEmpty)
diff --git a/test/WorkQueue/TestSuspendableWorkQueue.cpp b/test/WorkQueue/TestSuspendableWorkQueue.cpp
index 176b48f..5cf376c 100644
--- a/test/WorkQueue/TestSuspendableWorkQueue.cpp
+++ b/test/WorkQueue/TestSuspendableWorkQueue.cpp
@@ -32,25 +32,25 @@ public:
         resumableNotice(false),
         shutdownNotice(false) { }
 
-    void workAdded(Ice::Long, bool wasEmpty)
+    void workAdded(const QueueBasePtr&, Ice::Long, bool wasEmpty)
     {
         addedNotice = true;
         addedEmptyNotice = wasEmpty;
     }
 
-    void emptied()
+    void emptied(const QueueBasePtr&)
     {
         emptyNotice = true;
     }
 
-    void workResumable()
+    void workResumable(const QueueBasePtr&)
     {
         boost::unique_lock<boost::mutex> lock(mLock);
         resumableNotice = true;
         mCond.notify_one();
     }
 
-    void shuttingDown()
+    void shuttingDown(const QueueBasePtr&)
     {
         shutdownNotice = true;
     }
diff --git a/test/WorkQueue/TestWorkQueue.cpp b/test/WorkQueue/TestWorkQueue.cpp
index 3f60bb4..79f357d 100644
--- a/test/WorkQueue/TestWorkQueue.cpp
+++ b/test/WorkQueue/TestWorkQueue.cpp
@@ -31,24 +31,24 @@ public:
         addedEmptyNotice(false),
         emptyNotice(false), shutdownNotice(false) { }
 
-    void workAdded(Ice::Long numNewWork, bool wasEmpty)
+    void workAdded(const QueueBasePtr&, Ice::Long numNewWork, bool wasEmpty)
     {
         addedNotice = true;
         addedEmptyNotice = wasEmpty;
         tasksAdded = numNewWork;
     }
 
-    void emptied()
+    void emptied(const QueueBasePtr&)
     {
         emptyNotice = true;
     }
 
-    void workResumable()
+    void workResumable(const QueueBasePtr&)
     {
         BOOST_FAIL("workResumable called from a Queue?!");
     }
     
-    void shuttingDown()
+    void shuttingDown(const QueueBasePtr&)
     {
         shutdownNotice = true;
     }

commit d813bbcb95b2151ea23404268e18d2fcb891fd20
Author: Mark Michelson <mmichelson at digium.com>
Date:   Mon Jun 6 16:05:40 2011 -0500

    Changes based on slice changes to create a QueueBase interface.

diff --git a/include/AsteriskSCF/WorkQueue/DefaultQueueListener.h b/include/AsteriskSCF/WorkQueue/DefaultQueueListener.h
index 8190810..6169552 100644
--- a/include/AsteriskSCF/WorkQueue/DefaultQueueListener.h
+++ b/include/AsteriskSCF/WorkQueue/DefaultQueueListener.h
@@ -43,12 +43,14 @@ class DefaultQueueListenerPriv;
 class ASTERISK_SCF_ICEBOX_EXPORT DefaultQueueListener : public AsteriskSCF::System::WorkQueue::V1::QueueListener
 {
 public:
-    DefaultQueueListener(const AsteriskSCF::System::WorkQueue::V1::QueuePtr& queue);
+    DefaultQueueListener(const AsteriskSCF::System::WorkQueue::V1::QueueBasePtr& queue);
     ~DefaultQueueListener();
-    void workAdded(Ice::Long numNewWork, bool wasEmpty);
-    void workResumable();
-    void emptied();
-    void shuttingDown();
+    
+    void workAdded(const AsteriskSCF::System::WorkQueue::V1::QueueBasePtr&, Ice::Long numNewWork, bool wasEmpty);
+    void workResumable(const AsteriskSCF::System::WorkQueue::V1::QueueBasePtr&);
+    void emptied(const AsteriskSCF::System::WorkQueue::V1::QueueBasePtr&);
+    void shuttingDown(const AsteriskSCF::System::WorkQueue::V1::QueueBasePtr&);
+
 private:
     boost::shared_ptr<DefaultQueueListenerPriv> mPriv;
 };
diff --git a/src/ThreadPool/ThreadPool.cpp b/src/ThreadPool/ThreadPool.cpp
index ab7bda7..219335c 100644
--- a/src/ThreadPool/ThreadPool.cpp
+++ b/src/ThreadPool/ThreadPool.cpp
@@ -425,7 +425,7 @@ public:
     /**
      * Results in PoolListener::queueWorkAdded being called
      */
-    void workAdded(Ice::Long numNewWork, bool wasEmpty)
+    void workAdded(const QueueBasePtr&, Ice::Long numNewWork, bool wasEmpty)
     {
         mThreadPool->handleWorkAdded(numNewWork, wasEmpty);
     }
@@ -434,7 +434,7 @@ public:
      * Should never be called since a ThreadPool does not
      * use a SuspendableQueue
      */
-    void workResumable()
+    void workResumable(const QueueBasePtr&)
     {
         assert(false);
     }
@@ -442,12 +442,12 @@ public:
     /**
      * Results in PoolListener::queueEmptied being called
      */
-    void emptied()
+    void emptied(const QueueBasePtr&)
     {
         mThreadPool->handleEmptied();
     }
 
-    void shuttingDown()
+    void shuttingDown(const QueueBasePtr&)
     {
     }
 
diff --git a/src/WorkQueue/DefaultQueueListener.cpp b/src/WorkQueue/DefaultQueueListener.cpp
index c450339..82490b3 100644
--- a/src/WorkQueue/DefaultQueueListener.cpp
+++ b/src/WorkQueue/DefaultQueueListener.cpp
@@ -27,8 +27,8 @@ using namespace AsteriskSCF::System::WorkQueue::V1;
 class DefaultQueueListenerPriv
 {
 public:
-    DefaultQueueListenerPriv(const QueuePtr& queue)
-        : mWakeUp(false), mDead(false), mQueue(queue.get()),
+    DefaultQueueListenerPriv(const QueueBasePtr& queue)
+        : mWakeUp(false), mDead(false), mQueue(queue),
         mIsShutdown(false),
         mThread(boost::bind(&DefaultQueueListenerPriv::run, this)) { }
 
@@ -80,26 +80,17 @@ public:
 
     bool mWakeUp;
     bool mDead;
-    QueuePtr mQueue;
+    QueueBasePtr mQueue;
     boost::mutex mLock;
     boost::condition_variable mCond;
     bool mIsShutdown;
     boost::thread mThread;
 };
 
-DefaultQueueListener::DefaultQueueListener(const QueuePtr& queue)
+DefaultQueueListener::DefaultQueueListener(const QueueBasePtr& queue)
     : mPriv(new DefaultQueueListenerPriv(queue)) { }
 
-DefaultQueueListener::~DefaultQueueListener()
-{
-    if (!mPriv->mIsShutdown)
-    {
-        mPriv->setDead(true);
-        mPriv->mThread.join();
-    }
-}
-
-void DefaultQueueListener::workAdded(Ice::Long, bool wasEmpty)
+void DefaultQueueListener::workAdded(const QueueBasePtr&, Ice::Long, bool wasEmpty)
 {
     if (wasEmpty)
     {
@@ -107,16 +98,16 @@ void DefaultQueueListener::workAdded(Ice::Long, bool wasEmpty)
     }
 }
 
-void DefaultQueueListener::workResumable()
+void DefaultQueueListener::workResumable(const QueueBasePtr&)
 {
     mPriv->setDead(false);
 }
 
-void DefaultQueueListener::emptied()
+void DefaultQueueListener::emptied(const QueueBasePtr&)
 {
 }
 
-void DefaultQueueListener::shuttingDown()
+void DefaultQueueListener::shuttingDown(const QueueBasePtr&)
 {
     mPriv->mIsShutdown = true;
     mPriv->setDead(true);
diff --git a/src/WorkQueue/SuspendableWorkQueue.cpp b/src/WorkQueue/SuspendableWorkQueue.cpp
index e1a5c2a..b5346d2 100644
--- a/src/WorkQueue/SuspendableWorkQueue.cpp
+++ b/src/WorkQueue/SuspendableWorkQueue.cpp
@@ -204,8 +204,8 @@ public:
 class WorkListener : public SuspendableWorkListener
 {
 public:
-    WorkListener(boost::shared_ptr<SuspendableWorkQueuePriv> impl)
-        : mPriv(impl) { }
+    WorkListener(const QueueBasePtr& q, boost::shared_ptr<SuspendableWorkQueuePriv> impl)
+        : mPriv(impl), mQueue(q) { }
     void workResumable()
     {
         SuspendableWorkQueuePriv::WorkState previousState;
@@ -227,11 +227,12 @@ public:
         // suspended state.
         if (previousState == SuspendableWorkQueuePriv::Suspended)
         {
-            mPriv->mListener->workResumable();
+            mPriv->mListener->workResumable(mQueue);
         }
     }
 
     boost::shared_ptr<SuspendableWorkQueuePriv> mPriv;
+    QueueBasePtr mQueue;
 };
 
 SuspendableWorkQueue::SuspendableWorkQueue()
@@ -255,7 +256,7 @@ void SuspendableWorkQueue::enqueueWork(const SuspendableWorkPtr& work)
 
     if (listenerRef != 0)
     {
-        listenerRef->workAdded(1, wasEmpty);
+        listenerRef->workAdded(this, 1, wasEmpty);
     }
 }
 
@@ -274,7 +275,7 @@ void SuspendableWorkQueue::enqueueWorkSeq(const SuspendableWorkSeq& works)
 
     if (listenerRef != 0)
     {
-        listenerRef->workAdded(works.size(), wasEmpty);
+        listenerRef->workAdded(this, works.size(), wasEmpty);
     }
 }
 
@@ -305,7 +306,7 @@ void SuspendableWorkQueue::cancelWork(const SuspendableWorkPtr& work)
 
     if (isEmpty && listenerRef != 0)
     {
-        listenerRef->emptied();
+        listenerRef->emptied(this);
     }
 }
 
@@ -319,7 +320,7 @@ bool SuspendableWorkQueue::executeWork()
         return false;
     }
     
-    SuspendableWorkListenerPtr workListener(new WorkListener(mPriv));
+    SuspendableWorkListenerPtr workListener(new WorkListener(this, mPriv));
     SuspendableWorkResult result = work->execute(workListener);
 
     bool isEmpty;
@@ -362,7 +363,7 @@ bool SuspendableWorkQueue::executeWork()
     {
         if (listenerRef != 0)
         {
-            mPriv->mListener->emptied();
+            mPriv->mListener->emptied(this);
         }
         return false;
     }
@@ -388,7 +389,7 @@ void SuspendableWorkQueue::shutDown()
     boost::unique_lock<boost::shared_mutex> lock(mPriv->mLock);
     mPriv->checkForShuttingDown();
     mPriv->mShuttingDown = true;
-    mPriv->mListener->shuttingDown();
+    mPriv->mListener->shuttingDown(this);
 }
 
 }; //end namespace WorkQueue
diff --git a/src/WorkQueue/WorkQueue.cpp b/src/WorkQueue/WorkQueue.cpp
index 8119e18..fa50b5c 100644
--- a/src/WorkQueue/WorkQueue.cpp
+++ b/src/WorkQueue/WorkQueue.cpp
@@ -95,7 +95,7 @@ void WorkQueue::enqueueWork(const WorkPtr& work)
 
     if (listenerRef != 0)
     {
-        listenerRef->workAdded(1, wasEmpty);
+        listenerRef->workAdded(this, 1, wasEmpty);
     }
 }
 
@@ -113,7 +113,7 @@ void WorkQueue::enqueueWorkSeq(const WorkSeq& works)
 
     if (listenerRef != 0)
     {
-        listenerRef->workAdded(static_cast<long>(works.size()), wasEmpty);
+        listenerRef->workAdded(this, static_cast<long>(works.size()), wasEmpty);
     }
 }
 
@@ -139,7 +139,7 @@ void WorkQueue::cancelWork(const WorkPtr& work)
 
     if (isEmpty && listenerRef != 0)
     {
-        listenerRef->emptied();
+        listenerRef->emptied(this);
     }
 }
 
@@ -164,7 +164,7 @@ bool WorkQueue::executeWork()
     {
         if (listenerRef != 0)
         {
-            listenerRef->emptied();
+            listenerRef->emptied(this);
         }
         return false;
     }
@@ -190,7 +190,7 @@ void WorkQueue::shutDown()
     boost::unique_lock<boost::shared_mutex> lock(mPriv->mLock);
     mPriv->checkForShuttingDown();
     mPriv->mShuttingDown = true;
-    mPriv->mListener->shuttingDown();
+    mPriv->mListener->shuttingDown(this);
 }
 
 }; // end namespace WorkQueue

commit eb3e3d33fd4fbdb5e734bdac29572f9e2aab8c17
Author: Mark Michelson <mmichelson at digium.com>
Date:   Mon Jun 6 14:58:18 2011 -0500

    Make adjustments based on Kevin's feedback.
    
    * Add shutDown method for Queue and SuspendableQueue
    * Add shuttingDown method for QueueListener

diff --git a/include/AsteriskSCF/WorkQueue/DefaultQueueListener.h b/include/AsteriskSCF/WorkQueue/DefaultQueueListener.h
index 01b4090..8190810 100644
--- a/include/AsteriskSCF/WorkQueue/DefaultQueueListener.h
+++ b/include/AsteriskSCF/WorkQueue/DefaultQueueListener.h
@@ -48,6 +48,7 @@ public:
     void workAdded(Ice::Long numNewWork, bool wasEmpty);
     void workResumable();
     void emptied();
+    void shuttingDown();
 private:
     boost::shared_ptr<DefaultQueueListenerPriv> mPriv;
 };
diff --git a/include/AsteriskSCF/WorkQueue/SuspendableWorkQueue.h b/include/AsteriskSCF/WorkQueue/SuspendableWorkQueue.h
index d2b79be..8c3ba09 100644
--- a/include/AsteriskSCF/WorkQueue/SuspendableWorkQueue.h
+++ b/include/AsteriskSCF/WorkQueue/SuspendableWorkQueue.h
@@ -41,6 +41,7 @@ public:
     bool executeWork();
     Ice::Long getSize();
     void setListener(const AsteriskSCF::System::WorkQueue::V1::QueueListenerPtr& listener);
+    void shutDown();
 private:
     boost::shared_ptr<SuspendableWorkQueuePriv> mPriv;
 };
diff --git a/include/AsteriskSCF/WorkQueue/WorkQueue.h b/include/AsteriskSCF/WorkQueue/WorkQueue.h
index 0365537..f7aee13 100644
--- a/include/AsteriskSCF/WorkQueue/WorkQueue.h
+++ b/include/AsteriskSCF/WorkQueue/WorkQueue.h
@@ -40,6 +40,7 @@ public:
     bool executeWork();
     Ice::Long getSize();
     void setListener(const AsteriskSCF::System::WorkQueue::V1::QueueListenerPtr& listener);
+    void shutDown();
 private:
     boost::shared_ptr<WorkQueuePriv> mPriv;
 };
diff --git a/src/ThreadPool/ThreadPool.cpp b/src/ThreadPool/ThreadPool.cpp
index ac9aff3..ab7bda7 100644
--- a/src/ThreadPool/ThreadPool.cpp
+++ b/src/ThreadPool/ThreadPool.cpp
@@ -60,6 +60,7 @@ public:
         {
             boost::lock_guard<boost::mutex> lock(mQueueLock);
             mShuttingDown = true;
+            mControlQueue->shutDown();
             mControlQueue = 0;
         }
 
@@ -445,6 +446,11 @@ public:
     {
         mThreadPool->handleEmptied();
     }
+
+    void shuttingDown()
+    {
+    }
+
 private:
     ThreadPool *mThreadPool;
 };
diff --git a/src/WorkQueue/DefaultQueueListener.cpp b/src/WorkQueue/DefaultQueueListener.cpp
index cccf50b..c450339 100644
--- a/src/WorkQueue/DefaultQueueListener.cpp
+++ b/src/WorkQueue/DefaultQueueListener.cpp
@@ -29,6 +29,7 @@ class DefaultQueueListenerPriv
 public:
     DefaultQueueListenerPriv(const QueuePtr& queue)
         : mWakeUp(false), mDead(false), mQueue(queue.get()),
+        mIsShutdown(false),
         mThread(boost::bind(&DefaultQueueListenerPriv::run, this)) { }
 
     bool idle()
@@ -54,14 +55,22 @@ public:
         bool localDead = false;
         while (!localDead)
         {
-            if (!mQueue->executeWork())
+            try
             {
+                if (!mQueue->executeWork())
+                {
+                    localDead = idle();
+                }
+            }
+            catch (ShuttingDown)
+            {
+                //Just go idle if the queue has shut down.
                 localDead = idle();
             }
         }
     }
 
-    void setState(bool dead)
+    void setDead(bool dead)
     {
         boost::unique_lock<boost::mutex> lock(mLock);
         mWakeUp = true;
@@ -71,9 +80,10 @@ public:
 
     bool mWakeUp;
     bool mDead;
-    Queue *mQueue;
+    QueuePtr mQueue;
     boost::mutex mLock;
     boost::condition_variable mCond;
+    bool mIsShutdown;
     boost::thread mThread;
 };
 
@@ -82,26 +92,37 @@ DefaultQueueListener::DefaultQueueListener(const QueuePtr& queue)
 
 DefaultQueueListener::~DefaultQueueListener()
 {
-    mPriv->setState(true);
-    mPriv->mThread.join();
+    if (!mPriv->mIsShutdown)
+    {
+        mPriv->setDead(true);
+        mPriv->mThread.join();
+    }
 }
 
 void DefaultQueueListener::workAdded(Ice::Long, bool wasEmpty)
 {
     if (wasEmpty)
     {
-        mPriv->setState(false);
+        mPriv->setDead(false);
     }
 }
 
 void DefaultQueueListener::workResumable()
 {
-    mPriv->setState(false);
+    mPriv->setDead(false);
 }
 
 void DefaultQueueListener::emptied()
 {
 }
 
+void DefaultQueueListener::shuttingDown()
+{
+    mPriv->mIsShutdown = true;
+    mPriv->setDead(true);
+    mPriv->mThread.join();
+    mPriv->mQueue = 0;
+}
+
 }; //end namespace WorkQueue
 }; //end namespace AsteriskSCF
diff --git a/src/WorkQueue/SuspendableWorkQueue.cpp b/src/WorkQueue/SuspendableWorkQueue.cpp
index 771adc0..e1a5c2a 100644
--- a/src/WorkQueue/SuspendableWorkQueue.cpp
+++ b/src/WorkQueue/SuspendableWorkQueue.cpp
@@ -31,9 +31,9 @@ class SuspendableWorkQueuePriv
 {
 public:
     SuspendableWorkQueuePriv()
-        : mListener(0), state(Ready), currentWork(0) { }
+        : mListener(0), state(Ready), currentWork(0), mShuttingDown(false) { }
     SuspendableWorkQueuePriv(const QueueListenerPtr& listener)
-        : mListener(listener), state(Ready), currentWork(0) { }
+        : mListener(listener), state(Ready), currentWork(0), mShuttingDown(false) { }
 
     ~SuspendableWorkQueuePriv()
     {
@@ -55,6 +55,7 @@ public:
     {
         boost::unique_lock<boost::shared_mutex> lock(mLock);
 
+        checkForShuttingDown();
         SuspendableWorkPtr work;
         switch (state)
         {
@@ -82,6 +83,14 @@ public:
         return work;
     }
 
+    void checkForShuttingDown()
+    {
+        if (mShuttingDown)
+        {
+            throw ShuttingDown(__FILE__, __LINE__);
+        }
+    }
+
     QueueListenerPtr mListener;
     boost::shared_mutex mLock;
     std::deque<SuspendableWorkPtr> mQueue;
@@ -188,6 +197,8 @@ public:
      * when asked.
      */
     SuspendableWorkPtr currentWork;
+
+    bool mShuttingDown;
 };
 
 class WorkListener : public SuspendableWorkListener
@@ -235,6 +246,7 @@ void SuspendableWorkQueue::enqueueWork(const SuspendableWorkPtr& work)
     QueueListenerPtr listenerRef;
     {
         boost::unique_lock<boost::shared_mutex> lock(mPriv->mLock);
+        mPriv->checkForShuttingDown();
         //Call private version so we don't double grab the lock
         wasEmpty = mPriv->getSize() == 0; 
         mPriv->mQueue.push_back(work);
@@ -253,6 +265,7 @@ void SuspendableWorkQueue::enqueueWorkSeq(const SuspendableWorkSeq& works)
     QueueListenerPtr listenerRef;
     {
         boost::unique_lock<boost::shared_mutex> lock(mPriv->mLock);
+        mPriv->checkForShuttingDown();
         //Call private version so we don't double grab the lock
         wasEmpty = mPriv->getSize() == 0;
         mPriv->mQueue.insert(mPriv->mQueue.end(), works.begin(), works.end());
@@ -272,6 +285,8 @@ void SuspendableWorkQueue::cancelWork(const SuspendableWorkPtr& work)
     {
         boost::unique_lock<boost::shared_mutex> lock(mPriv->mLock);
 
+        mPriv->checkForShuttingDown();
+
         if (work == mPriv->currentWork)
         {
             throw WorkInProgress(__FILE__, __LINE__);
@@ -357,14 +372,24 @@ bool SuspendableWorkQueue::executeWork()
 Ice::Long SuspendableWorkQueue::getSize()
 {
     boost::shared_lock<boost::shared_mutex> lock(mPriv->mLock);
+    mPriv->checkForShuttingDown();
     return mPriv->getSize();
 }
 
 void SuspendableWorkQueue::setListener(const QueueListenerPtr& listener)
 {
     boost::unique_lock<boost::shared_mutex> lock(mPriv->mLock);
+    mPriv->checkForShuttingDown();
     mPriv->mListener = listener;
 }
 
+void SuspendableWorkQueue::shutDown()
+{
+    boost::unique_lock<boost::shared_mutex> lock(mPriv->mLock);
+    mPriv->checkForShuttingDown();
+    mPriv->mShuttingDown = true;
+    mPriv->mListener->shuttingDown();
+}
+
 }; //end namespace WorkQueue
 }; //end namespace AsteriskSCF
diff --git a/src/WorkQueue/WorkQueue.cpp b/src/WorkQueue/WorkQueue.cpp
index d31cf25..8119e18 100644
--- a/src/WorkQueue/WorkQueue.cpp
+++ b/src/WorkQueue/WorkQueue.cpp
@@ -31,9 +31,9 @@ class WorkQueuePriv
 {
 public:
     WorkQueuePriv()
-        : mListener(0) { }
+        : mListener(0), mShuttingDown(false) { }
     WorkQueuePriv(const QueueListenerPtr& listener)
-        : mListener(listener) { }
+        : mListener(listener), mShuttingDown(false) { }
 
     ~WorkQueuePriv()
     {
@@ -46,6 +46,7 @@ public:
     WorkPtr getNextTask()
     {
         boost::unique_lock<boost::shared_mutex> lock(mLock);
+        checkForShuttingDown();
         if (mQueue.empty())
         {
             return 0;
@@ -56,9 +57,22 @@ public:
         return work;
     }
 
+    /**
+     * Throw an exception if the queue is shutting down.
+     * This should be called with mLock locked.
+     */
+    void checkForShuttingDown()
+    {
+        if (mShuttingDown)
+        {
+            throw ShuttingDown(__FILE__, __LINE__);
+        }
+    }
+
     QueueListenerPtr mListener;
     boost::shared_mutex mLock;
     std::deque<WorkPtr> mQueue;
+    bool mShuttingDown;
 };
 
 WorkQueue::WorkQueue()
@@ -73,6 +87,7 @@ void WorkQueue::enqueueWork(const WorkPtr& work)
     QueueListenerPtr listenerRef;
     {
         boost::unique_lock<boost::shared_mutex> lock(mPriv->mLock);
+        mPriv->checkForShuttingDown();
         wasEmpty = mPriv->mQueue.empty();
         listenerRef = mPriv->mListener;
         mPriv->mQueue.push_back(work);
@@ -90,6 +105,7 @@ void WorkQueue::enqueueWorkSeq(const WorkSeq& works)
     QueueListenerPtr listenerRef;
     {
         boost::unique_lock<boost::shared_mutex> lock(mPriv->mLock);
+        mPriv->checkForShuttingDown();
         wasEmpty = mPriv->mQueue.empty();
         listenerRef = mPriv->mListener;
         mPriv->mQueue.insert(mPriv->mQueue.end(), works.begin(), works.end());
@@ -108,6 +124,8 @@ void WorkQueue::cancelWork(const WorkPtr& work)
     {
         boost::unique_lock<boost::shared_mutex> lock(mPriv->mLock);
 
+        mPriv->checkForShuttingDown();
+
         std::deque<WorkPtr>::iterator i = std::find(mPriv->mQueue.begin(), mPriv->mQueue.end(), work);
         if (i == mPriv->mQueue.end())
         {
@@ -156,14 +174,24 @@ bool WorkQueue::executeWork()
 Ice::Long WorkQueue::getSize()
 {
     boost::shared_lock<boost::shared_mutex> lock(mPriv->mLock);
+    mPriv->checkForShuttingDown();
     return static_cast<long>(mPriv->mQueue.size());
 }
 
 void WorkQueue::setListener(const QueueListenerPtr& listener)
 {
     boost::unique_lock<boost::shared_mutex> lock(mPriv->mLock);
+    mPriv->checkForShuttingDown();
     mPriv->mListener = listener;
 }
 
+void WorkQueue::shutDown()
+{
+    boost::unique_lock<boost::shared_mutex> lock(mPriv->mLock);
+    mPriv->checkForShuttingDown();
+    mPriv->mShuttingDown = true;
+    mPriv->mListener->shuttingDown();
+}
+
 }; // end namespace WorkQueue
 }; // end namespace AsteriskSCF
diff --git a/test/ThreadPool/TestThreadPool.cpp b/test/ThreadPool/TestThreadPool.cpp
index 05b032f..081cfaa 100644
--- a/test/ThreadPool/TestThreadPool.cpp
+++ b/test/ThreadPool/TestThreadPool.cpp
@@ -193,6 +193,8 @@ BOOST_AUTO_TEST_CASE(addWork)
     BOOST_CHECK(listener->mActive == 0);
     BOOST_CHECK(listener->mIdle == 0);
     BOOST_CHECK(listener->mZombie == 0);
+
+    queue->shutDown();
 }
 
 BOOST_AUTO_TEST_CASE(threadCreation)
@@ -214,6 +216,7 @@ BOOST_AUTO_TEST_CASE(threadCreation)
     BOOST_CHECK(listener->mIdle == 1);
     BOOST_CHECK(listener->mActive == 0);
     BOOST_CHECK(listener->mZombie == 0);
+    queue->shutDown();
 }
 
 BOOST_AUTO_TEST_CASE(threadDestruction)
@@ -240,6 +243,7 @@ BOOST_AUTO_TEST_CASE(threadDestruction)
     BOOST_CHECK(listener->mIdle == 2);
     BOOST_CHECK(listener->mActive == 0);
     BOOST_CHECK(listener->mZombie == 0);
+    queue->shutDown();
 }
 
 BOOST_AUTO_TEST_CASE(oneTaskOneThread)
@@ -271,6 +275,7 @@ BOOST_AUTO_TEST_CASE(oneTaskOneThread)
     BOOST_CHECK(listener->mIdle == 1);
     BOOST_CHECK(listener->mActive == 0);
     BOOST_CHECK(listener->mZombie == 0);
+    queue->shutDown();
 }
 
 BOOST_AUTO_TEST_CASE(oneThreadOneTask)
@@ -304,6 +309,7 @@ BOOST_AUTO_TEST_CASE(oneThreadOneTask)
     BOOST_CHECK(listener->mIdle == 1);
     BOOST_CHECK(listener->mActive == 0);
     BOOST_CHECK(listener->mZombie == 0);
+    queue->shutDown();
 }
 
 BOOST_AUTO_TEST_CASE(oneThreadMultipleTasks)
@@ -342,6 +348,7 @@ BOOST_AUTO_TEST_CASE(oneThreadMultipleTasks)
     BOOST_CHECK(listener->mIdle == 1);
     BOOST_CHECK(listener->mActive == 0);
     BOOST_CHECK(listener->mZombie == 0);
+    queue->shutDown();
 }
 
 BOOST_AUTO_TEST_CASE(reactivation)
@@ -384,6 +391,8 @@ BOOST_AUTO_TEST_CASE(reactivation)
     BOOST_CHECK(listener->mIdle == 1);
     BOOST_CHECK(listener->mActive == 0);
     BOOST_CHECK(listener->mZombie == 0);
+
+    queue->shutDown();
 }
 
 BOOST_AUTO_TEST_CASE(taskDistribution)
@@ -435,6 +444,7 @@ BOOST_AUTO_TEST_CASE(taskDistribution)
     BOOST_CHECK(listener->mIdle == 2);
     BOOST_CHECK(listener->mActive == 0);
     BOOST_CHECK(listener->mZombie == 0);
+    queue->shutDown();
 }
 
 BOOST_AUTO_TEST_CASE(zombies)
@@ -548,5 +558,4 @@ BOOST_AUTO_TEST_CASE(moreThreadDestruction)
     BOOST_CHECK(listener->mIdle == 1);
     BOOST_CHECK(listener->mZombie == 0);
 }
-
 BOOST_AUTO_TEST_SUITE_END()
diff --git a/test/WorkQueue/TestSuspendableWorkQueue.cpp b/test/WorkQueue/TestSuspendableWorkQueue.cpp
index 78276ee..176b48f 100644
--- a/test/WorkQueue/TestSuspendableWorkQueue.cpp
+++ b/test/WorkQueue/TestSuspendableWorkQueue.cpp
@@ -29,7 +29,8 @@ public:
         : addedNotice(false),
         addedEmptyNotice(false),
         emptyNotice(false),
-        resumableNotice(false) { }
+        resumableNotice(false),
+        shutdownNotice(false) { }
 
     void workAdded(Ice::Long, bool wasEmpty)
     {
@@ -49,10 +50,16 @@ public:
         mCond.notify_one();
     }
 
+    void shuttingDown()
+    {
+        shutdownNotice = true;
+    }
+
     bool addedNotice;
     bool addedEmptyNotice;
     bool emptyNotice;
     bool resumableNotice;
+    bool shutdownNotice;
     boost::mutex mLock;
     boost::condition_variable mCond;
 };
@@ -183,6 +190,10 @@ BOOST_AUTO_TEST_CASE(addWork)
     BOOST_CHECK(listener->addedNotice == true);
     BOOST_CHECK(listener->addedEmptyNotice == true);
     BOOST_CHECK(queue->getSize() == 1);
+
+    queue->shutDown();
+
+    BOOST_CHECK(listener->shutdownNotice == true);
 }
 
 BOOST_AUTO_TEST_CASE(addWorkSeq)
@@ -201,6 +212,86 @@ BOOST_AUTO_TEST_CASE(addWorkSeq)
     BOOST_CHECK(listener->addedEmptyNotice == true);
     BOOST_CHECK(listener->emptyNotice == false);
     BOOST_CHECK(queue->getSize() == 2);
+
+    queue->shutDown();
+
+    BOOST_CHECK(listener->shutdownNotice == true);
+}
+
+BOOST_AUTO_TEST_CASE(shutDownException)
+{
+    TestListenerPtr listener(new TestListener);
+    SuspendableQueuePtr queue(new SuspendableWorkQueue(listener));
+
+    queue->shutDown();
+
+    bool excepted;
+    try
+    {
+        queue->getSize();
+    }
+    catch (ShuttingDown)
+    {
+        excepted = true;
+    }
+    BOOST_CHECK(excepted == true);
+
+    excepted = false;
+    SimpleTaskPtr work(new SimpleTask);
+    try
+    {
+        queue->enqueueWork(work);
+    }
+    catch (ShuttingDown)
+    {
+        excepted = true;
+    }
+    BOOST_CHECK(excepted == true);
+    excepted = false;
+
+    try
+    {
+        queue->executeWork();
+    }
+    catch (ShuttingDown)
+    {
+        excepted = true;
+    }
+    BOOST_CHECK(excepted == true);
+    excepted = false;
+
+    try
+    {
+        queue->cancelWork(work);
+    }
+    catch (ShuttingDown)
+    {
+        excepted = true;
+    }
+    BOOST_CHECK(excepted == true);
+    excepted = false;
+
+    try
+    {
+        queue->setListener(listener);
+    }
+    catch (ShuttingDown)
+    {
+        excepted = true;
+    }
+    BOOST_CHECK(excepted == true);
+    excepted = false;
+
+    try
+    {
+        queue->shutDown();
+    }
+    catch (ShuttingDown)
+    {
+        excepted = true;
+    }
+    BOOST_CHECK(excepted == true);
+
 }
 
 BOOST_AUTO_TEST_CASE(appendWork)
@@ -219,6 +310,10 @@ BOOST_AUTO_TEST_CASE(appendWork)
     BOOST_CHECK(listener->addedEmptyNotice == false);
     BOOST_CHECK(listener->emptyNotice == false);
     BOOST_CHECK(queue->getSize() == 2);
+
+    queue->shutDown();
+
+    BOOST_CHECK(listener->shutdownNotice == true);
 }
 
 BOOST_AUTO_TEST_CASE(cancelWork)
@@ -242,6 +337,10 @@ BOOST_AUTO_TEST_CASE(cancelWork)
     BOOST_CHECK(excepted == false);
     BOOST_CHECK(listener->emptyNotice == true);
     BOOST_CHECK(queue->getSize() == 0);
+
+    queue->shutDown();
+
+    BOOST_CHECK(listener->shutdownNotice == true);
 }
 
 BOOST_AUTO_TEST_CASE(cancelNonExistent1)
@@ -265,6 +364,10 @@ BOOST_AUTO_TEST_CASE(cancelNonExistent1)
     BOOST_CHECK(listener->addedEmptyNotice == false);
     BOOST_CHECK(listener->emptyNotice == false);
     BOOST_CHECK(queue->getSize() == 0);
+
+    queue->shutDown();
+
+    BOOST_CHECK(listener->shutdownNotice == true);
 }
 
 BOOST_AUTO_TEST_CASE(cancelNonExistent2)
@@ -288,6 +391,10 @@ BOOST_AUTO_TEST_CASE(cancelNonExistent2)
 
     BOOST_CHECK(excepted == false);
     BOOST_CHECK(queue->getSize() == 1);
+
+    queue->shutDown();
+
+    BOOST_CHECK(listener->shutdownNotice == true);
 }
 
 BOOST_AUTO_TEST_CASE(simpleWorkExecution)
@@ -303,6 +410,10 @@ BOOST_AUTO_TEST_CASE(simpleWorkExecution)
     BOOST_CHECK(work->taskExecuted == true);
     BOOST_CHECK(listener->emptyNotice == true);
     BOOST_CHECK(queue->getSize() == 0);
+
+    queue->shutDown();
+
+    BOOST_CHECK(listener->shutdownNotice == true);
 }
 
 BOOST_AUTO_TEST_CASE(executeNonExistent)
@@ -315,6 +426,10 @@ BOOST_AUTO_TEST_CASE(executeNonExistent)
     BOOST_CHECK(moreWork == false);
     BOOST_CHECK(queue->getSize() == 0);
     BOOST_CHECK(listener->emptyNotice == false);
+
+    queue->shutDown();
+
+    BOOST_CHECK(listener->shutdownNotice == true);
 }
 
 BOOST_AUTO_TEST_CASE(executionOrder1)
@@ -339,6 +454,10 @@ BOOST_AUTO_TEST_CASE(executionOrder1)
     BOOST_CHECK(work2->taskExecuted == true);
     BOOST_CHECK(listener->emptyNotice == true);
     BOOST_CHECK(queue->getSize() == 0);
+
+    queue->shutDown();
+
+    BOOST_CHECK(listener->shutdownNotice == true);
 }
 
 BOOST_AUTO_TEST_CASE(executionOrder2)
@@ -387,6 +506,10 @@ BOOST_AUTO_TEST_CASE(executionOrder2)
     BOOST_CHECK(work4->taskExecuted == true);
     BOOST_CHECK(listener->emptyNotice == true);
     BOOST_CHECK(queue->getSize() == 0);
+
+    queue->shutDown();
+
+    BOOST_CHECK(listener->shutdownNotice == true);
 }
 
 // Begin unique SuspendableWorkQueue tests
@@ -457,6 +580,10 @@ BOOST_AUTO_TEST_CASE(complexWork)
     BOOST_CHECK(queue->getSize() == 0);
     BOOST_CHECK(work->currentState == ComplexTask::Task2Complete);
     BOOST_CHECK(listener->emptyNotice == true);
+
+    queue->shutDown();
+
+    BOOST_CHECK(listener->shutdownNotice == true);
 }
 
 BOOST_AUTO_TEST_CASE(racyWork)
@@ -484,6 +611,10 @@ BOOST_AUTO_TEST_CASE(racyWork)
     BOOST_CHECK(work->currentState == RacyTask::Task2Complete);
     BOOST_CHECK(queue->getSize() == 0);
     BOOST_CHECK(listener->emptyNotice == true);
+
+    queue->shutDown();
+
+    BOOST_CHECK(listener->shutdownNotice == true);
 }
 
 BOOST_AUTO_TEST_SUITE_END()
diff --git a/test/WorkQueue/TestWorkQueue.cpp b/test/WorkQueue/TestWorkQueue.cpp
index 535cece..3f60bb4 100644
--- a/test/WorkQueue/TestWorkQueue.cpp
+++ b/test/WorkQueue/TestWorkQueue.cpp
@@ -29,7 +29,7 @@ public:
     TestListener()
         : tasksAdded(0), addedNotice(false),
         addedEmptyNotice(false),
-        emptyNotice(false) { }
+        emptyNotice(false), shutdownNotice(false) { }
 
     void workAdded(Ice::Long numNewWork, bool wasEmpty)
     {
@@ -47,11 +47,17 @@ public:
     {
         BOOST_FAIL("workResumable called from a Queue?!");
     }
+    
+    void shuttingDown()
+    {
+        shutdownNotice = true;
+    }
 
     Ice::Long tasksAdded;
     bool addedNotice;
     bool addedEmptyNotice;
     bool emptyNotice;
+    bool shutdownNotice;
 };
 
 typedef IceUtil::Handle<TestListener> TestListenerPtr;
@@ -105,6 +111,85 @@ BOOST_AUTO_TEST_CASE(addWork)
     BOOST_CHECK(listener->addedEmptyNotice == true);
     BOOST_CHECK(listener->tasksAdded == 1);
     BOOST_CHECK(queue->getSize() == 1);
+
+    queue->shutDown();
+
+    BOOST_CHECK(listener->shutdownNotice == true);
+}
+
+BOOST_AUTO_TEST_CASE(shutDownException)
+{
+    TestListenerPtr listener(new TestListener);
+    QueuePtr queue(new WorkQueue(listener));
+
+    queue->shutDown();
+
+    bool excepted;
+    try
+    {
+        queue->getSize();
+    }
+    catch (ShuttingDown)
+    {
+        excepted = true;
+    }
+    BOOST_CHECK(excepted == true);
+
+    excepted = false;
+    TaskPtr work(new Task);
+    try
+    {
+        queue->enqueueWork(work);
+    }
+    catch (ShuttingDown)
+    {
+        excepted = true;
+    }
+    BOOST_CHECK(excepted == true);
+    excepted = false;
+
+    try
+    {
+        queue->executeWork();
+    }
+    catch (ShuttingDown)
+    {
+        excepted = true;
+    }
+    BOOST_CHECK(excepted == true);
+    excepted = false;
+
+    try
+    {
+        queue->cancelWork(work);
+    }
+    catch (ShuttingDown)
+    {
+        excepted = true;
+    }
+    BOOST_CHECK(excepted == true);
+    excepted = false;
+
+    try
+    {
+        queue->setListener(listener);
+    }
+    catch (ShuttingDown)
+    {
+        excepted = true;
+    }
+    BOOST_CHECK(excepted == true);
+    excepted = false;
+
+    try
+    {
+        queue->shutDown();
+    }
+    catch (ShuttingDown)
+    {
+        excepted = true;
+    }
+    BOOST_CHECK(excepted == true);
 }
 
 BOOST_AUTO_TEST_CASE(addWorkSeq)
@@ -124,6 +209,10 @@ BOOST_AUTO_TEST_CASE(addWorkSeq)
     BOOST_CHECK(listener->emptyNotice == false);
     BOOST_CHECK(listener->tasksAdded == 2);
     BOOST_CHECK(queue->getSize() == 2);
+
+    queue->shutDown();
+
+    BOOST_CHECK(listener->shutdownNotice == true);
 }
 
 BOOST_AUTO_TEST_CASE(appendWork)
@@ -143,6 +232,10 @@ BOOST_AUTO_TEST_CASE(appendWork)
     BOOST_CHECK(listener->emptyNotice == false);
     BOOST_CHECK(listener->tasksAdded == 1);
     BOOST_CHECK(queue->getSize() == 2);
+
+    queue->shutDown();
+
+    BOOST_CHECK(listener->shutdownNotice == true);
 }
 
 BOOST_AUTO_TEST_CASE(cancelWork)
@@ -157,6 +250,10 @@ BOOST_AUTO_TEST_CASE(cancelWork)
 
     BOOST_CHECK(listener->emptyNotice == true);
     BOOST_CHECK(queue->getSize() == 0);
+
+    queue->shutDown();
+
+    BOOST_CHECK(listener->shutdownNotice == true);
 }
 
 BOOST_AUTO_TEST_CASE(cancelNonExistent1)
@@ -171,6 +268,10 @@ BOOST_AUTO_TEST_CASE(cancelNonExistent1)
     BOOST_CHECK(listener->addedEmptyNotice == false);
     BOOST_CHECK(listener->emptyNotice == false);
     BOOST_CHECK(queue->getSize() == 0);
+
+    queue->shutDown();
+
+    BOOST_CHECK(listener->shutdownNotice == true);
 }
 
 BOOST_AUTO_TEST_CASE(cancelNonExistent2)
@@ -185,6 +286,10 @@ BOOST_AUTO_TEST_CASE(cancelNonExistent2)
     queue->cancelWork(work2);
 
     BOOST_CHECK(queue->getSize() == 1);
+
+    queue->shutDown();
+
+    BOOST_CHECK(listener->shutdownNotice == true);
 }
 
 BOOST_AUTO_TEST_CASE(workExecution)
@@ -200,6 +305,10 @@ BOOST_AUTO_TEST_CASE(workExecution)
     BOOST_CHECK(work->taskExecuted == true);
     BOOST_CHECK(listener->emptyNotice == true);
     BOOST_CHECK(queue->getSize() == 0);
+
+    queue->shutDown();
+
+    BOOST_CHECK(listener->shutdownNotice == true);
 }
 
 BOOST_AUTO_TEST_CASE(executeNonExistent)
@@ -212,6 +321,10 @@ BOOST_AUTO_TEST_CASE(executeNonExistent)
     BOOST_CHECK(moreWork == false);
     BOOST_CHECK(queue->getSize() == 0);
     BOOST_CHECK(listener->emptyNotice == false);
+
+    queue->shutDown();
+
+    BOOST_CHECK(listener->shutdownNotice == true);
 }
 
 BOOST_AUTO_TEST_CASE(executionOrder1)
@@ -236,6 +349,10 @@ BOOST_AUTO_TEST_CASE(executionOrder1)
     BOOST_CHECK(work2->taskExecuted == true);
     BOOST_CHECK(listener->emptyNotice == true);
     BOOST_CHECK(queue->getSize() == 0);
+
+    queue->shutDown();
+
+    BOOST_CHECK(listener->shutdownNotice == true);
 }
 
 BOOST_AUTO_TEST_CASE(executionOrder2)
@@ -284,6 +401,10 @@ BOOST_AUTO_TEST_CASE(executionOrder2)
     BOOST_CHECK(work4->taskExecuted == true);
     BOOST_CHECK(listener->emptyNotice == true);
     BOOST_CHECK(queue->getSize() == 0);
+
+    queue->shutDown();
+
+    BOOST_CHECK(listener->shutdownNotice == true);
 }
 
 void waitForTaskCompletion(NotifyTaskPtr& task)

-----------------------------------------------------------------------


-- 
asterisk-scf/release/ice-util-cpp.git



More information about the asterisk-scf-commits mailing list