[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
Sat Mar 19 13:25:59 CDT 2011


branch "workqueue" has been updated
       via  b1fe5a2bdb1df7cb951802f2944179eba62bfed8 (commit)
       via  419b47ed5ad7dcfe9e6e01cee19ee925c029c1c4 (commit)
       via  358a442c8020f9fd311727f8f41385aa7f29287e (commit)
      from  0b63a5b84f4fe69291c94f9bcaed9561059a467e (commit)

Summary of changes:
 WorkQueue/src/SuspendableWorkQueue.cpp      |   11 ++++---
 WorkQueue/test/TestSuspendableWorkQueue.cpp |   44 ++++++++++++++++++++++-----
 2 files changed, 42 insertions(+), 13 deletions(-)


- Log -----------------------------------------------------------------
commit b1fe5a2bdb1df7cb951802f2944179eba62bfed8
Author: Mark Michelson <mmichelson at digium.com>
Date:   Sat Mar 19 13:25:27 2011 -0500

    Add some checks to be sure the listener's workResumable() is called when we expect.

diff --git a/WorkQueue/test/TestSuspendableWorkQueue.cpp b/WorkQueue/test/TestSuspendableWorkQueue.cpp
index 99fdd85..e2cbf98 100644
--- a/WorkQueue/test/TestSuspendableWorkQueue.cpp
+++ b/WorkQueue/test/TestSuspendableWorkQueue.cpp
@@ -517,6 +517,8 @@ BOOST_AUTO_TEST_CASE(complexWork)
     }
     lock.unlock();
 
+    BOOST_CHECK(listener->resumableNotice == true);
+
     //Now attempting to execute work should result in
     //something actually happening.
 
@@ -542,6 +544,7 @@ BOOST_AUTO_TEST_CASE(racyWork)
     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,
     //we should be able to tell it to execute work.

commit 419b47ed5ad7dcfe9e6e01cee19ee925c029c1c4
Author: Mark Michelson <mmichelson at digium.com>
Date:   Sat Mar 19 13:21:46 2011 -0500

    Reorder some code for clarity and add a new assertion.

diff --git a/WorkQueue/src/SuspendableWorkQueue.cpp b/WorkQueue/src/SuspendableWorkQueue.cpp
index bbf3e1a..d645582 100644
--- a/WorkQueue/src/SuspendableWorkQueue.cpp
+++ b/WorkQueue/src/SuspendableWorkQueue.cpp
@@ -267,6 +267,7 @@ bool SuspendableWorkQueue::executeWork()
     SuspendableWorkPtr work;
     if (mImpl->state == SuspendableWorkQueueImpl::Ready)
     {
+        assert(mImpl->currentWork == 0);
         if (mImpl->q.empty())
         {
             return false;
@@ -302,14 +303,14 @@ bool SuspendableWorkQueue::executeWork()
         // can forego setting the state to Suspended and instead
         // treat the situation as if the work's execution had
         // actually returned "Complete"
-        if (mImpl->state != SuspendableWorkQueueImpl::Resumable)
+        if (mImpl->state == SuspendableWorkQueueImpl::Resumable)
         {
-            mImpl->state = SuspendableWorkQueueImpl::Suspended;
-            return false;
+            return true;
         }
-        else
+        else //State is still "Executing"
         {
-            return true;
+            mImpl->state = SuspendableWorkQueueImpl::Suspended;
+            return false;
         }
     }
     

commit 358a442c8020f9fd311727f8f41385aa7f29287e
Author: Mark Michelson <mmichelson at digium.com>
Date:   Sat Mar 19 13:17:34 2011 -0500

    Fix synchronization in ComplexTask test.
    
    My use of conditionals didn't quite do the trick, resulting
    in occasional test failures. I made these adjustments and ran
    the test about 30 times and saw no failures.

diff --git a/WorkQueue/test/TestSuspendableWorkQueue.cpp b/WorkQueue/test/TestSuspendableWorkQueue.cpp
index 8b8c578..99fdd85 100644
--- a/WorkQueue/test/TestSuspendableWorkQueue.cpp
+++ b/WorkQueue/test/TestSuspendableWorkQueue.cpp
@@ -69,9 +69,22 @@ public:
 
 typedef IceUtil::Handle<SimpleTask> SimpleTaskPtr;
 
-static boost::condition_variable globalCond;
+// A ComplexTask creates a thread to simulate
+// An asynchronous task. When asyncTaskCond is
+// notified, this simulates the completion of
+// the asynchronous task
+static boost::condition_variable asyncTaskCond;
+static bool asyncTaskComplete;
+// workResumableCond is used by the ComplexTask to
+// notify the testing thread that it has
+// finished notifying the SuspendableQueue
+// that work may be resumed.
+static boost::condition_variable workResumableCond;
+static bool isWorkResumable;
+
+// Lock used in conjunction with the condition
+// variables.
 static boost::mutex globalLock;
-static bool globalGoOn;
 
 class ComplexTask : public SuspendableWork
 {
@@ -81,8 +94,8 @@ public:
     ~ComplexTask()
     {
         boost::unique_lock<boost::mutex> lock(globalLock);
-        globalGoOn = true;
-        globalCond.notify_one();
+        asyncTaskComplete = true;
+        asyncTaskCond.notify_one();
         lock.unlock();
         mThread.join();
     }
@@ -108,12 +121,15 @@ public:
     void thread()
     {
         boost::unique_lock<boost::mutex> lock(globalLock);
-        while (!globalGoOn)
+        while (!asyncTaskComplete)
         {
-            globalCond.wait(lock);
+            asyncTaskCond.wait(lock);
         }
         lock.unlock();
         mListener->workResumable();
+        lock.lock();
+        isWorkResumable = true;
+        workResumableCond.notify_one();
     }
     enum State
     {
@@ -487,9 +503,18 @@ BOOST_AUTO_TEST_CASE(complexWork)
     BOOST_CHECK(queue->workCount() == 1);
     BOOST_CHECK(work->currentState == ComplexTask::Task1Complete);
 
+    // We simulate the ComplexTasks asynchronous task here in
+    // the testing thread.
     boost::unique_lock<boost::mutex> lock(globalLock);
-    globalGoOn = true;
-    globalCond.notify_one();
+    asyncTaskComplete = true;
+    asyncTaskCond.notify_one();
+    lock.unlock();
+
+    lock.lock();
+    while (!isWorkResumable)
+    {
+        workResumableCond.wait(lock);
+    }
     lock.unlock();
 
     //Now attempting to execute work should result in

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


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



More information about the asterisk-scf-commits mailing list