Properly monitor timeout on ThreadGate for Framework.waitForStop().
(FELIX-1279)


git-svn-id: https://svn.apache.org/repos/asf/felix/trunk@788845 13f79535-47bb-0310-9956-ffa450edef68
diff --git a/framework/src/main/java/org/apache/felix/framework/util/ThreadGate.java b/framework/src/main/java/org/apache/felix/framework/util/ThreadGate.java
index 9546f7a..158ee14 100644
--- a/framework/src/main/java/org/apache/felix/framework/util/ThreadGate.java
+++ b/framework/src/main/java/org/apache/felix/framework/util/ThreadGate.java
@@ -43,9 +43,19 @@
     **/
     public synchronized void await(long timeout) throws InterruptedException
     {
+        long start = System.currentTimeMillis();
+        long remaining = timeout;
         while (!m_open)
         {
-            wait(timeout);
+            wait(remaining);
+            if (timeout > 0)
+            {
+                remaining = timeout - (System.currentTimeMillis() - start);
+                if (remaining <= 0)
+                {
+                    break;
+                }
+            }
         }
     }
 }
\ No newline at end of file