[SCM] master: Wrap calls to wait() and await() with loops to avoid spurious wakeups

moore@sourceware.org moore@sourceware.org
Tue Nov 27 17:20:00 GMT 2007


The branch, master has been updated
       via  e2e6135d1b8db0d4b46a2e6901bbb4cd1139fea3 (commit)
      from  f2d100dad2256b784de45495b1ea9a71e2b6ff5b (commit)

Those revisions listed above that are new to this repository have
not appeared on any other notification email.

- Log -----------------------------------------------------------------
commit e2e6135d1b8db0d4b46a2e6901bbb4cd1139fea3
Author: Tim Moore <moore@blackbox.bricoworks.com>
Date:   Tue Nov 27 18:19:57 2007 +0100

    Wrap calls to wait() and await() with loops to avoid spurious wakeups
    
    frysk-core/frysk/event/ChangeLog
    2007-11-27  Tim Moore  <timoore@redhat.com>
    
    	* Request.java (Handler.execute, Handler.request): Wait inside a
    	loop, testing for an execute flag.
    
    frysk-core/frysk/hpd/ChangeLog
    2007-11-27  Tim Moore  <timoore@redhat.com>
    
    	* CLI.java (doAttach): Wrap await call inside loop in order to
    	disregard InterruptedException.
    	* QuitCommand.java (interpret): ditto
    	* RunCommand.java (run): ditto
    
    frysk-core/frysk/rt/ChangeLog
    2007-11-27  Tim Moore  <timoore@redhat.com>
    
    	* BreakpointManager.java (manageProcess): Wrap await call inside
    	loop in order to disregard InterruptedException.
    
    frysk-core/frysk/util/ChangeLog
    2007-11-27  Tim Moore  <timoore@redhat.com>
    
    	* TestCountDownLatch.java (testCounters): Wrap await in while loop.

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

Summary of changes:
 frysk-core/frysk/event/ChangeLog              |    5 +++++
 frysk-core/frysk/event/Request.java           |   18 ++++++++++++------
 frysk-core/frysk/hpd/CLI.java                 |   24 +++++++++++++-----------
 frysk-core/frysk/hpd/ChangeLog                |    7 +++++++
 frysk-core/frysk/hpd/QuitCommand.java         |   11 +++++++----
 frysk-core/frysk/hpd/RunCommand.java          |   10 ++++++----
 frysk-core/frysk/rt/BreakpointManager.java    |   11 +++++++----
 frysk-core/frysk/rt/ChangeLog                 |    5 +++++
 frysk-core/frysk/util/ChangeLog               |    4 ++++
 frysk-core/frysk/util/TestCountDownLatch.java |    8 +++++++-
 10 files changed, 73 insertions(+), 30 deletions(-)

First 500 lines of diff:
diff --git a/frysk-core/frysk/event/ChangeLog b/frysk-core/frysk/event/ChangeLog
index 8bf2f70..9cfcd38 100644
--- a/frysk-core/frysk/event/ChangeLog
+++ b/frysk-core/frysk/event/ChangeLog
@@ -1,3 +1,8 @@
+2007-11-27  Tim Moore  <timoore@redhat.com>
+
+	* Request.java (Handler.execute, Handler.request): Wait inside a
+	loop, testing for an execute flag.
+
 2007-05-07  Tim Moore  <timoore@redhat.com>
 
 	* WaitEventLoop.java (signalBuilder.signal): Print signal name
diff --git a/frysk-core/frysk/event/Request.java b/frysk-core/frysk/event/Request.java
index bbf0b5b..3374eac 100644
--- a/frysk-core/frysk/event/Request.java
+++ b/frysk-core/frysk/event/Request.java
@@ -62,6 +62,7 @@ public abstract class Request
 	implements Event
     {
 	private RuntimeException runtimeException;
+        private boolean executed = false;
 	public synchronized void execute ()
 	{
 	    try {
@@ -70,18 +71,23 @@ public abstract class Request
 	    catch (RuntimeException r) {
 		runtimeException = r;
 	    }
+            executed = true;
 	    notify();
 	}
 	private synchronized void request ()
 	{
 	    runtimeException = null;
 	    eventLoop.add(this);
-	    try {
-		wait();
-	    }
-	    catch (InterruptedException r) {
-		throw new RuntimeException (r);
-	    }
+            while (!executed) {
+                try {
+                    wait();
+                    if (executed)
+                        break;
+                }
+                catch (InterruptedException r) {
+                }   
+            }
+            executed = false;   // Can requests ever be recycled?
 	    if (runtimeException != null)
 		throw runtimeException;
 	}
diff --git a/frysk-core/frysk/hpd/CLI.java b/frysk-core/frysk/hpd/CLI.java
index 1c5ef5c..032caa3 100644
--- a/frysk-core/frysk/hpd/CLI.java
+++ b/frysk-core/frysk/hpd/CLI.java
@@ -146,18 +146,20 @@ public class CLI {
         }
         steppingEngine.addProc(proc);
 	// Wait till we are attached.
-        try {
-            attachedLatch.await();
-	    outWriter.print("Attached to process ");
-	    outWriter.println(attached);
-        } catch (InterruptedException ie) {
-            throw new RuntimeException("attachLatch interrupted");
-        } finally {
-            synchronized (this) {
-                attached = -1;
-                attachedLatch = null;
-            }
+        while (true) {
+            try {
+                attachedLatch.await();
+                outWriter.print("Attached to process ");
+                outWriter.println(attached);
+                synchronized (this) {
+                    attached = -1;
+                    attachedLatch = null;
+                }
+                break;
+            } catch (InterruptedException ie) {
+            }            
         }
+
         steppingEngine.getBreakpointManager().manageProcess(proc);
         // If passed a taskID < 0, request a reserved ProcID
         if (this.taskID < 0)
diff --git a/frysk-core/frysk/hpd/ChangeLog b/frysk-core/frysk/hpd/ChangeLog
index e3de710..6386fb4 100644
--- a/frysk-core/frysk/hpd/ChangeLog
+++ b/frysk-core/frysk/hpd/ChangeLog
@@ -1,3 +1,10 @@
+2007-11-27  Tim Moore  <timoore@redhat.com>
+
+	* CLI.java (doAttach): Wrap await call inside loop in order to
+	disregard InterruptedException.
+	* QuitCommand.java (interpret): ditto
+	* RunCommand.java (run): ditto
+
 2007-11-22  Rick Moseley  <rmoseley@redhat.com>
 
 	* TestPeekCommand.java: Fix bz #5396; added test for when
diff --git a/frysk-core/frysk/hpd/QuitCommand.java b/frysk-core/frysk/hpd/QuitCommand.java
index 20680c1..4bb3e14 100644
--- a/frysk-core/frysk/hpd/QuitCommand.java
+++ b/frysk-core/frysk/hpd/QuitCommand.java
@@ -97,10 +97,13 @@ class QuitCommand extends ParameterizedCommand {
     void interpret(CLI cli, Input cmd, Object options) {
         CountDownLatch quitLatch = new CountDownLatch(1);
         new KillRequest(cli, quitLatch).request();
-        try {
-            quitLatch.await();
-        }
-        catch (InterruptedException e) {
+        while (true) {
+            try {
+                quitLatch.await();
+                break;
+            }
+            catch (InterruptedException e) {
+            }
         }
 	cli.addMessage("Quitting...", Message.TYPE_NORMAL);
 	DetachCommand detachCommand = new DetachCommand();
diff --git a/frysk-core/frysk/hpd/RunCommand.java b/frysk-core/frysk/hpd/RunCommand.java
index 3f8a0b1..edc4501 100644
--- a/frysk-core/frysk/hpd/RunCommand.java
+++ b/frysk-core/frysk/hpd/RunCommand.java
@@ -171,10 +171,12 @@ class RunCommand extends ParameterizedCommand {
     private void run(CLI cli, Input cmd) {
 	Runner runner = new Runner(cli);
 	Manager.host.requestCreateAttachedProc(cmd.stringArrayValue(), runner);
-        try {
-            runner.latch.await();
-        } catch (InterruptedException e) {
-            return;
+        while (true) {
+            try {
+                runner.latch.await();
+                break;
+            } catch (InterruptedException e) {
+            }
         }
         // register with SteppingEngine et.al.
         cli.doAttach(runner.launchedTask.getProc());
diff --git a/frysk-core/frysk/rt/BreakpointManager.java b/frysk-core/frysk/rt/BreakpointManager.java
index d1737d8..87dffa0 100644
--- a/frysk-core/frysk/rt/BreakpointManager.java
+++ b/frysk-core/frysk/rt/BreakpointManager.java
@@ -262,10 +262,13 @@ public class BreakpointManager
                 }
             },
             sharedLibBptAddr);
-        try {
-            codeObserverLatch.await();
-        }
-        catch (InterruptedException e) {
+        while (true) {
+            try {
+                codeObserverLatch.await();
+                break;
+            }
+            catch (InterruptedException e) {
+            }
         }
     }
 }
diff --git a/frysk-core/frysk/rt/ChangeLog b/frysk-core/frysk/rt/ChangeLog
index b7ac848..d4afa91 100644
--- a/frysk-core/frysk/rt/ChangeLog
+++ b/frysk-core/frysk/rt/ChangeLog
@@ -1,3 +1,8 @@
+2007-11-27  Tim Moore  <timoore@redhat.com>
+
+	* BreakpointManager.java (manageProcess): Wrap await call inside
+	loop in order to disregard InterruptedException.
+
 2007-11-16  Rick Moseley  <rmoseley@redhat.com>
 
 	* ProcTaskIDManager.java(removeProcID,manageProcSelect): New.
diff --git a/frysk-core/frysk/util/ChangeLog b/frysk-core/frysk/util/ChangeLog
index 13120ed..c5d7cc7 100644
--- a/frysk-core/frysk/util/ChangeLog
+++ b/frysk-core/frysk/util/ChangeLog
@@ -1,3 +1,7 @@
+2007-11-27  Tim Moore  <timoore@redhat.com>
+
+	* TestCountDownLatch.java (testCounters): Wrap await in while loop.
+
 2007-11-26  Sami Wagiaalla  <swagiaal@redhat.com>
 
 	Added a boolean for printing source	libraries to Frame.toPrint().
diff --git a/frysk-core/frysk/util/TestCountDownLatch.java b/frysk-core/frysk/util/TestCountDownLatch.java
index 6c6a2b4..61b687a 100644
--- a/frysk-core/frysk/util/TestCountDownLatch.java
+++ b/frysk-core/frysk/util/TestCountDownLatch.java
@@ -60,7 +60,13 @@ public class TestCountDownLatch
         thread1.start();
         thread2.start();
         thread3.start();
-        latch.await();
+        while (true) {
+            try {
+                latch.await();
+                break;
+            } catch (InterruptedException e) {
+            }
+        }
         assertEquals("count", latch.getCount(), 0);
     }
 


hooks/post-receive
--
frysk system monitor/debugger



More information about the Frysk-cvs mailing list