1414package org .eclipse .ui .tests .harness .util ;
1515
1616import java .util .concurrent .CountDownLatch ;
17- import java .util .concurrent .TimeUnit ;
1817
1918import org .eclipse .jface .preference .IPreferenceStore ;
2019import org .eclipse .swt .SWTException ;
3635 */
3736public class RCPTestWorkbenchAdvisor extends WorkbenchAdvisor {
3837
39- public static Boolean asyncDuringStartup = null ;
38+ public Boolean asyncDuringStartup = null ;
4039
4140 // the following fields are set by the threads that attempt sync/asyncs
4241 // during startup.
43- public static volatile Boolean syncWithDisplayAccess = null ;
44- public static volatile Boolean asyncWithDisplayAccess = null ;
45- public static volatile Boolean syncWithoutDisplayAccess = null ;
46- public static volatile Boolean asyncWithoutDisplayAccess = null ;
42+ public volatile Boolean syncWithDisplayAccess = null ;
43+ public volatile Boolean asyncWithDisplayAccess = null ;
44+ public volatile Boolean syncWithoutDisplayAccess = null ;
45+ public volatile Boolean asyncWithoutDisplayAccess = null ;
4746
48- private static boolean started = false ;
47+ private boolean started = false ;
4948
5049 // CountDownLatch to wait for async/sync operations with DisplayAccess to complete
5150 // We need to wait for 2 operations: asyncWithDisplayAccess and syncWithDisplayAccess
52- private static CountDownLatch displayAccessLatch = null ;
51+ private CountDownLatch displayAccessLatch = null ;
5352
54- public static boolean isSTARTED () {
55- synchronized (RCPTestWorkbenchAdvisor .class ) {
56- return started ;
57- }
53+ public synchronized boolean isStarted () {
54+ return started ;
5855 }
5956
6057 /** Default value of -1 causes the option to be ignored. */
@@ -66,7 +63,7 @@ public static boolean isSTARTED() {
6663 * Traps whether or not calls to displayAccess in the UI thread resulted in
6764 * an exception. Should be false.
6865 */
69- public static boolean displayAccessInUIThreadAllowed ;
66+ public boolean displayAccessInUIThreadAllowed ;
7067
7168 public RCPTestWorkbenchAdvisor () {
7269 // default value means the advisor will not trigger the workbench to
@@ -135,14 +132,14 @@ public void preStartup() {
135132
136133 if (display != null ) {
137134 display .asyncExec (() -> {
138- asyncDuringStartup = !isSTARTED ();
135+ asyncDuringStartup = !isStarted ();
139136 });
140137 }
141138
142139 // start a bunch of threads that are going to do a/sync execs. For some
143140 // of them, call DisplayAccess.accessDisplayDuringStartup. For others,
144141 // dont. Those that call this method should have their runnables invoked
145- // prior to the method isSTARTED returning true.
142+ // prior to the method isStarted returning true.
146143
147144 setupAsyncDisplayThread (true , display );
148145 setupSyncDisplayThread (true , display );
@@ -167,13 +164,13 @@ public void run() {
167164 try {
168165 display .syncExec (() -> {
169166 if (callDisplayAccess ) {
170- syncWithDisplayAccess = !isSTARTED ();
167+ syncWithDisplayAccess = !isStarted ();
171168 // Count down after the runnable executes
172169 if (displayAccessLatch != null ) {
173170 displayAccessLatch .countDown ();
174171 }
175172 } else {
176- syncWithoutDisplayAccess = !isSTARTED ();
173+ syncWithoutDisplayAccess = !isStarted ();
177174 }
178175 });
179176 } catch (SWTException e ) {
@@ -198,13 +195,13 @@ public void run() {
198195 DisplayAccess .accessDisplayDuringStartup ();
199196 display .asyncExec (() -> {
200197 if (callDisplayAccess ) {
201- asyncWithDisplayAccess = !isSTARTED ();
198+ asyncWithDisplayAccess = !isStarted ();
202199 // Count down after the runnable executes
203200 if (displayAccessLatch != null ) {
204201 displayAccessLatch .countDown ();
205202 }
206203 } else {
207- asyncWithoutDisplayAccess = !isSTARTED ();
204+ asyncWithoutDisplayAccess = !isStarted ();
208205 }
209206 });
210207 }
@@ -219,23 +216,21 @@ public void postStartup() {
219216
220217 // Wait for async/sync operations with DisplayAccess to complete execution
221218 if (displayAccessLatch != null ) {
222- try {
223- // Wait up to 5 seconds for operations with DisplayAccess to complete
224- // This ensures they execute BEFORE we mark started = true
225- boolean completed = displayAccessLatch .await (5 , TimeUnit .SECONDS );
226- if (!completed ) {
227- System .err .println ("WARNING: Timeout waiting for async/sync operations with DisplayAccess" );
219+ long limit = System .currentTimeMillis () + 10000 ;
220+ while (displayAccessLatch .getCount () > 0 && System .currentTimeMillis () < limit ) {
221+ if (!Display .getCurrent ().readAndDispatch ()) {
222+ Display .getCurrent ().sleep ();
228223 }
229- } catch ( InterruptedException e ) {
230- Thread . currentThread (). interrupt ();
231- System .err .println ("WARNING: Interrupted while waiting for async/sync operations" );
224+ }
225+ if ( displayAccessLatch . getCount () > 0 ) {
226+ System .err .println ("WARNING: Timeout waiting for async/sync operations with DisplayAccess " );
232227 }
233228 }
234229
235230 // Now mark as started - operations with DisplayAccess should have completed
236231 // Operations without DisplayAccess should still be pending (deferred)
237- synchronized (RCPTestWorkbenchAdvisor . class ) {
232+ synchronized (this ) {
238233 started = true ;
239234 }
240235 }
241- }
236+ }
0 commit comments