Skip to content

Commit

Permalink
Future
Browse files Browse the repository at this point in the history
- Switched to `Condition` + `Mutex` technique
  • Loading branch information
deavmi committed Oct 1, 2023
1 parent c2880f3 commit 974cc5e
Showing 1 changed file with 16 additions and 9 deletions.
25 changes: 16 additions & 9 deletions source/guillotine/future.d
Original file line number Diff line number Diff line change
Expand Up @@ -3,9 +3,8 @@
*/
module guillotine.future;

// TODO: Examine the below import which seemingly fixes stuff for libsnooze
import libsnooze.clib;
import libsnooze;
import core.sync.mutex : Mutex;
import core.sync.condition : Condition;

import guillotine.result : Result;

Expand All @@ -26,9 +25,16 @@ public enum State
public final class Future
{
/**
* `libsnooze` event
* Mutex for condition
* variable
*/
private Event event;
private Mutex mutex;

/**
* Condition variable
* used for signalling
*/
private Condition signal;

/**
* State of the future
Expand All @@ -50,7 +56,8 @@ public final class Future
*/
public this()
{
this.event = new Event();
this.mutex = new Mutex();
this.signal = new Condition(this.mutex);
}

/**
Expand Down Expand Up @@ -89,7 +96,7 @@ public final class Future
{
try
{
event.wait();
signal.wait();
doneYet = true;
}
catch(InterruptedException e)
Expand Down Expand Up @@ -137,7 +144,7 @@ public final class Future
this.state = State.FINISHED;

// Wake up any sleepers
this.event.notifyAll();
this.signal.notifyAll();
}

/**
Expand All @@ -158,6 +165,6 @@ public final class Future
this.state = State.ERRORED;

// Wake up any sleepers
this.event.notifyAll();
this.signal.notifyAll();
}
}

0 comments on commit 974cc5e

Please sign in to comment.