SRADA-737: Added wait/notify on DAState for a preparation phase finished.
authorMaria Guseva <m.guseva@samsung.com>
Tue, 7 Jun 2016 16:49:19 +0000 (19:49 +0300)
committerMaria Guseva <m.guseva@samsung.com>
Fri, 1 Jul 2016 08:24:02 +0000 (17:24 +0900)
Now DAState notifies all waiters that are waiting for DAState to be changed
to INIT, RUNNING or DONE which means that a preparation phase is finished.

Change-Id: I79c78e8886538a82007764f73c76217bf9b23521

org.tizen.dynamicanalyzer/src/org/tizen/dynamicanalyzer/common/DAState.java

index 476ee85..0c27cca 100644 (file)
@@ -47,6 +47,11 @@ public enum DAState {
         */
        private static final Condition doneCondition = stateLock.newCondition();
 
+       /**
+        * Condition lock used to notify waiters when state is consistent (not PREPARE_*).
+        */
+       private static final Condition preparedCondition = stateLock.newCondition();
+
        public static DAState getCurrentState() {
                return currentState;
        }
@@ -62,11 +67,13 @@ public enum DAState {
                        case DONE:
                                currentState = state;
                                doneCondition.signalAll();
+                               preparedCondition.signalAll();
                                ret = true;
                                break;
                        case RUNNING:
                                if (currentState == PREPARE_START) {
                                        currentState = state;
+                                       preparedCondition.signalAll();
                                        ret = true;
                                }
                                break;
@@ -113,6 +120,22 @@ public enum DAState {
                }
        }
 
+       /**
+        * Blocks caller thread until DA state doesn't become consistent.
+        * 
+        * @throws InterruptedException if waiting was interrupted
+        */
+       public static void waitPrepared() throws InterruptedException {
+               stateLock.lock();
+               try {
+                       while (!isRunning() && !isStartable()) {
+                               preparedCondition.await();
+                       }
+               } finally {
+                       stateLock.unlock();
+               }
+       }
+
        public static boolean isRunning() {
                return (currentState == RUNNING);
        }