[asterisk-scf-commits] asterisk-scf/integration/ice-util-cpp.git branch "workqueue" updated.

Commits to the Asterisk SCF project code repositories asterisk-scf-commits at lists.digium.com
Tue Mar 22 09:58:59 CDT 2011


branch "workqueue" has been updated
       via  1ac48658c2ecb86905f1f589c71be87fa42775c6 (commit)
       via  b60a58e2f3375326545f4442f2df26e95b41fe11 (commit)
      from  b8309cfcd44dc344c2d5589e9d04eaf820827068 (commit)

Summary of changes:
 WorkQueue/src/SuspendableWorkQueue.cpp      |   38 +++++++++++---------------
 WorkQueue/src/WorkQueue.cpp                 |   23 +++++++++-------
 WorkQueue/test/TestSuspendableWorkQueue.cpp |   14 +++++----
 3 files changed, 37 insertions(+), 38 deletions(-)


- Log -----------------------------------------------------------------
commit 1ac48658c2ecb86905f1f589c71be87fa42775c6
Author: Mark Michelson <mmichelson at digium.com>
Date:   Mon Mar 21 17:10:08 2011 -0500

    Add data to WorkExists and SuspendableWorkExists exceptions.

diff --git a/WorkQueue/src/SuspendableWorkQueue.cpp b/WorkQueue/src/SuspendableWorkQueue.cpp
index d645582..5bd6a9f 100644
--- a/WorkQueue/src/SuspendableWorkQueue.cpp
+++ b/WorkQueue/src/SuspendableWorkQueue.cpp
@@ -185,19 +185,14 @@ void SuspendableWorkQueue::enqueueWork(const SuspendableWorkPtr &work)
 {
     boost::unique_lock<boost::mutex> lock(mImpl->mLock);
 
-    if (work == mImpl->currentWork)
+    if (work == mImpl->currentWork ||
+            std::find(mImpl->q.begin(), mImpl->q.end(), work) != mImpl->q.end())
     {
-        throw WorkExists();
+        SuspendableWorkSeq exceptionItems;
+        exceptionItems.push_back(work);
+        throw SuspendableWorkExists(__FILE__, __LINE__, exceptionItems);
     }
     
-    if (std::find(mImpl->q.begin(), mImpl->q.end(), work) != mImpl->q.end())
-    {
-        //XXX When slice2cpp bug is cleared, we'll want
-        //to actually include the duplicated work item in
-        //the exception
-        throw WorkExists();
-    }
-
     bool wasEmpty = mImpl->q.empty();
     mImpl->q.push_back(work);
     lock.unlock();
@@ -208,22 +203,21 @@ void SuspendableWorkQueue::enqueueWorkSeq(const SuspendableWorkSeq &works)
 {
     boost::unique_lock<boost::mutex> lock(mImpl->mLock);
     
+    SuspendableWorkSeq exceptionItems;
     for (SuspendableWorkSeq::const_iterator iter = works.begin(); iter != works.end(); ++iter)
     {
-        if (*iter == mImpl->currentWork)
+        if (*iter == mImpl->currentWork ||
+                std::find(mImpl->q.begin(), mImpl->q.end(), *iter) != mImpl->q.end())
         {
-            throw WorkExists();
-        }
-        if (std::find(mImpl->q.begin(), mImpl->q.end(), *iter) != mImpl->q.end())
-        {
-            //XXX When slice2cpp bug is cleared, we'll need
-            //not to throw the exception immediately. Instead,
-            //we'll keep a running list of duplicated items so
-            //we can throw an exception with all duplicated items.
-            throw WorkExists();
+            exceptionItems.push_back(*iter);
         }
     }
 
+    if (!exceptionItems.empty())
+    {
+        throw SuspendableWorkExists(__FILE__, __LINE__, exceptionItems);
+    }
+
     bool wasEmpty = mImpl->q.empty();
     mImpl->q.insert(mImpl->q.end(), works.begin(), works.end());
     lock.unlock();
@@ -236,13 +230,13 @@ void SuspendableWorkQueue::cancelWork(const SuspendableWorkPtr &work)
 
     if (work == mImpl->currentWork)
     {
-        throw WorkNotFound();
+        throw WorkNotFound(__FILE__, __LINE__);
     }
 
     std::deque<SuspendableWorkPtr>::iterator i = std::find(mImpl->q.begin(), mImpl->q.end(), work);
     if (i == mImpl->q.end())
     {
-        throw WorkNotFound();
+        throw WorkNotFound(__FILE__, __LINE__);
     }
 
     mImpl->q.erase(i);
diff --git a/WorkQueue/src/WorkQueue.cpp b/WorkQueue/src/WorkQueue.cpp
index 0f1a1ea..0b22843 100644
--- a/WorkQueue/src/WorkQueue.cpp
+++ b/WorkQueue/src/WorkQueue.cpp
@@ -51,10 +51,11 @@ void WorkQueue::enqueueWork(const WorkPtr &work)
     
     if (std::find(mImpl->q.begin(), mImpl->q.end(), work) != mImpl->q.end())
     {
-        //XXX When slice2cpp bug is cleared, we'll want
-        //to actually include the duplicated work item in
-        //the exception
-        throw WorkExists();
+        WorkSeq exceptionItems;
+        exceptionItems.push_back(work);
+        //XXX The file and line number are required because
+        //of a limitation regarding local exceptions in Ice.
+        throw WorkExists(__FILE__, __LINE__, exceptionItems);
     }
 
     bool wasEmpty = mImpl->q.empty();
@@ -67,18 +68,20 @@ void WorkQueue::enqueueWorkSeq(const WorkSeq &works)
 {
     boost::unique_lock<boost::mutex> lock(mImpl->mLock);
     
+    WorkSeq exceptionItems;
     for (WorkSeq::const_iterator iter = works.begin(); iter != works.end(); ++iter)
     {
         if (std::find(mImpl->q.begin(), mImpl->q.end(), *iter) != mImpl->q.end())
         {
-            //XXX When slice2cpp bug is cleared, we'll need
-            //not to throw the exception immediately. Instead,
-            //we'll keep a running list of duplicated items so
-            //we can throw an exception with all duplicated items.
-            throw WorkExists();
+            exceptionItems.push_back(*iter);
         }
     }
 
+    if (!exceptionItems.empty())
+    {
+        throw WorkExists(__FILE__, __LINE__, exceptionItems);
+    }
+
     bool wasEmpty = mImpl->q.empty();
     mImpl->q.insert(mImpl->q.end(), works.begin(), works.end());
     lock.unlock();
@@ -92,7 +95,7 @@ void WorkQueue::cancelWork(const WorkPtr &work)
     std::deque<WorkPtr>::iterator i = std::find(mImpl->q.begin(), mImpl->q.end(), work);
     if (i == mImpl->q.end())
     {
-        throw WorkNotFound();
+        throw WorkNotFound(__FILE__, __LINE__);
     }
 
     mImpl->q.erase(i);

commit b60a58e2f3375326545f4442f2df26e95b41fe11
Author: Mark Michelson <mmichelson at digium.com>
Date:   Mon Mar 21 16:40:45 2011 -0500

    Add some comments to the suspendable work queue test.

diff --git a/WorkQueue/test/TestSuspendableWorkQueue.cpp b/WorkQueue/test/TestSuspendableWorkQueue.cpp
index 1ef4a85..8a8aced 100644
--- a/WorkQueue/test/TestSuspendableWorkQueue.cpp
+++ b/WorkQueue/test/TestSuspendableWorkQueue.cpp
@@ -478,6 +478,8 @@ BOOST_AUTO_TEST_CASE(executionOrder2)
     BOOST_CHECK(queue->workCount() == 0);
 }
 
+// Begin unique SuspendableWorkQueue tests
+
 BOOST_AUTO_TEST_CASE(complexWork)
 {
     TestListenerPtr listener(new TestListener);
@@ -492,23 +494,23 @@ BOOST_AUTO_TEST_CASE(complexWork)
     BOOST_CHECK(queue->workCount() == 1);
     BOOST_CHECK(work->currentState == ComplexTask::Task1Complete);
 
-    //Until we poke the ComplexWork's thread, the queue
+    //Until we poke the ComplexTask's thread, the queue
     //should be in a suspended state, thereby not actually
     //attempting to execute anything.
-
     moreWork = queue->executeWork();
 
     BOOST_CHECK(moreWork == false);
     BOOST_CHECK(queue->workCount() == 1);
     BOOST_CHECK(work->currentState == ComplexTask::Task1Complete);
 
-    // We simulate the ComplexTasks asynchronous task here in
+    // We simulate the ComplexTask's asynchronous task here in
     // the testing thread.
     boost::unique_lock<boost::mutex> lock(globalLock);
     asyncTaskComplete = true;
     asyncTaskCond.notify_one();
     lock.unlock();
 
+    // Now we wait to be told work may be resumed.
     lock.lock();
     while (!listener->resumableNotice)
     {
@@ -516,11 +518,11 @@ BOOST_AUTO_TEST_CASE(complexWork)
     }
     lock.unlock();
 
+    // Yeah it's redundant, so sue me.
     BOOST_CHECK(listener->resumableNotice == true);
 
     //Now attempting to execute work should result in
     //something actually happening.
-
     moreWork = queue->executeWork();
 
     BOOST_CHECK(moreWork == false);
@@ -540,14 +542,14 @@ BOOST_AUTO_TEST_CASE(racyWork)
     bool moreWork = queue->executeWork();
 
     BOOST_CHECK(moreWork == true);
+    BOOST_CHECK(listener->resumableNotice == false);
     BOOST_CHECK(work->currentState == RacyTask::Task1Complete);
     BOOST_CHECK(queue->workCount() == 1);
     BOOST_CHECK(listener->emptyNotice == false);
-    BOOST_CHECK(listener->resumableNotice == false);
 
     //Because the queue was already told work was resumable,
+    //and thus returned true to us from executeWork(),
     //we should be able to tell it to execute work.
-
     moreWork = queue->executeWork();
 
     BOOST_CHECK(moreWork == false);

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


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



More information about the asterisk-scf-commits mailing list