Flutter Engine
The Flutter Engine
Public Member Functions | Package Functions | Package Attributes | List of all members
org.dartlang.vm.service.OpLatch Class Reference
Inheritance diagram for org.dartlang.vm.service.OpLatch:
org.dartlang.vm.service.ResultLatch< T >

Public Member Functions

void opWorking ()
 

Package Functions

void opComplete ()
 
void waitAndAssertOpComplete ()
 
boolean waitOpComplete ()
 

Package Attributes

final CountDownLatch latch = new CountDownLatch(1)
 

Detailed Description

OpLatch is used by one thread to wait for another thread to complete (see OpLatch#waitOpComplete() and OpLatch#waitAndAssertOpComplete()). If the operation does not complete before the expiration time then OpLatch#waitOpComplete() returns false and OpLatch#waitAndAssertOpComplete() throws an exception.

Definition at line 25 of file OpLatch.java.

Member Function Documentation

◆ opComplete()

void org.dartlang.vm.service.OpLatch.opComplete ( )
inlinepackage

Call to indicate that the operation completed successfully.

Definition at line 40 of file OpLatch.java.

40 {
41 latch.countDown();
42 }
final CountDownLatch latch
Definition: OpLatch.java:26

◆ opWorking()

void org.dartlang.vm.service.OpLatch.opWorking ( )
inline

Set or increase the time after which the operation is considered failed. This is automatically called by waitAndAssertOp() and waitOpComplete().

Definition at line 33 of file OpLatch.java.

33 {
34 endTime = System.currentTimeMillis() + 5000;
35 }

◆ waitAndAssertOpComplete()

void org.dartlang.vm.service.OpLatch.waitAndAssertOpComplete ( )
inlinepackage

Wait for the operation to complete or the time limit to expire. Periodically call opWorking() to increase the expiration time. Throw a RuntimeException if the operation did not complete before the expiration time.

Definition at line 49 of file OpLatch.java.

49 {
50 if (!waitOpComplete()) {
51 System.out.println(">>> No response received");
52 throw new RuntimeException("No response received");
53 }
54 }

◆ waitOpComplete()

boolean org.dartlang.vm.service.OpLatch.waitOpComplete ( )
inlinepackage

Wait for the operation to complete or the time limit to expire. Periodically call opWorking() to increase the expiration time.

Returns
true if the operation completed, or false otherwise

Definition at line 62 of file OpLatch.java.

62 {
63 opWorking();
64 while (true) {
65 long waitTimeMillis = endTime - System.currentTimeMillis();
66 if (waitTimeMillis <= 0) {
67 return latch.getCount() == 0;
68 }
69 try {
70 if (latch.await(waitTimeMillis, TimeUnit.MILLISECONDS)) {
71 return true;
72 }
73 } catch (InterruptedException e) {
74 // ignore and loop to check if timeout has changed
75 }
76 }
77 }

Member Data Documentation

◆ latch

final CountDownLatch org.dartlang.vm.service.OpLatch.latch = new CountDownLatch(1)
package

Definition at line 26 of file OpLatch.java.


The documentation for this class was generated from the following file: