Skip to content
Browse files

Still more S17-Concurrency up-to-specness

keeper -> vow
  • Loading branch information...
1 parent 42960c4 commit 186b4511251e884fae386e32a57d12d4f0fc054d @lizmat lizmat committed Nov 8, 2013
Showing with 40 additions and 40 deletions.
  1. +9 −9 src/vm/jvm/core/Channel.pm
  2. +31 −31 src/vm/jvm/core/Promise.pm
View
18 src/vm/jvm/core/Channel.pm
@@ -14,8 +14,8 @@ my class Channel {
# received and the channel is thus closed.
has $!closed_promise;
- # Closed promise's keeper.
- has $!closed_promise_keeper;
+ # Closed promise's vow.
+ has $!closed_promise_vow;
# Flag for if the channel is closed to senders.
has $!closed;
@@ -30,7 +30,7 @@ my class Channel {
my \LinkedBlockingQueue := $interop.typeForName('java.util.concurrent.LinkedBlockingQueue');
$!queue := LinkedBlockingQueue.'constructor/new/()V'();
$!closed_promise = Promise.new;
- $!closed_promise_keeper = $!closed_promise.keeper;
+ $!closed_promise_vow = $!closed_promise.vow;
}
method send(Channel:D: \item) {
@@ -41,11 +41,11 @@ my class Channel {
method receive(Channel:D:) {
my \msg := $interop.javaObjectToSixmodel($!queue.take());
if nqp::istype(msg, CHANNEL_CLOSE) {
- $!closed_promise_keeper.keep(Nil);
+ $!closed_promise_vow.keep(Nil);
X::Channel::ReceiveOnClosed.new.throw
}
elsif nqp::istype(msg, CHANNEL_FAIL) {
- $!closed_promise_keeper.break(msg.error);
+ $!closed_promise_vow.break(msg.error);
die msg.error;
}
msg
@@ -58,11 +58,11 @@ my class Channel {
} else {
my \msg := $interop.javaObjectToSixmodel(fetched);
if nqp::istype(msg, CHANNEL_CLOSE) {
- $!closed_promise_keeper.keep(Nil);
+ $!closed_promise_vow.keep(Nil);
Nil
}
elsif nqp::istype(msg, CHANNEL_FAIL) {
- $!closed_promise_keeper.break(msg.error);
+ $!closed_promise_vow.break(msg.error);
Nil
}
else {
@@ -78,11 +78,11 @@ my class Channel {
} else {
my \msg := $interop.javaObjectToSixmodel(fetched);
if nqp::istype(msg, CHANNEL_CLOSE) {
- $!closed_promise_keeper.keep(Nil);
+ $!closed_promise_vow.keep(Nil);
Nil
}
elsif nqp::istype(msg, CHANNEL_FAIL) {
- $!closed_promise_keeper.break(msg.error);
+ $!closed_promise_vow.break(msg.error);
Nil
}
else {
View
62 src/vm/jvm/core/Promise.pm
@@ -9,14 +9,14 @@ my class X::Promise::Combinator is Exception {
my class X::Promise::CauseOnlyValidOnBroken is Exception {
method message() { "Can only call cause on a broken promise" }
}
-my class X::Promise::KeeperTaken is Exception {
- method message() { "Access denied to keep/break this Promise; the keeper was already taken" }
+my class X::Promise::Vowed is Exception {
+ method message() { "Access denied to keep/break this Promise; already vowed" }
}
my class Promise {
has $.scheduler;
has $.status;
has $!result;
- has int $!keeper_taken;
+ has int $!vow_taken;
has Mu $!ready_semaphore;
has Mu $!lock;
has @!thens;
@@ -30,12 +30,12 @@ my class Promise {
$!status = Planned;
}
- # A Promise::Keeper is used to enable the right to keep/break a promise
- # to be restricted to a given "owner". Taking the keeper for a Promise
+ # A Promise::Vow is used to enable the right to keep/break a promise
+ # to be restricted to a given "owner". Taking the Vow for a Promise
# prevents anybody else from getting hold of it.
- class Keeper { ... }
- trusts Keeper;
- class Keeper {
+ class Vow { ... }
+ trusts Vow;
+ class Vow {
has $.promise;
method keep(\result) {
$!promise!Promise::keep(result)
@@ -44,21 +44,21 @@ my class Promise {
$!promise!Promise::break(exception)
}
}
- method keeper() {
+ method vow() {
$!lock.lock();
- if $!keeper_taken {
+ if $!vow_taken {
$!lock.unlock();
- X::Promise::KeeperTaken.new.throw
+ X::Promise::Vowed.new.throw
}
- my $k := nqp::create(Keeper);
- nqp::bindattr($k, Keeper, '$!promise', self);
- $!keeper_taken = 1;
+ my $vow := nqp::create(Vow);
+ nqp::bindattr($vow, Vow, '$!promise', self);
+ $!vow_taken = 1;
$!lock.unlock();
- $k
+ $vow
}
method keep(Promise:D: $result) {
- self.keeper.keep($result)
+ self.vow.keep($result)
}
method !keep($!result) {
@@ -69,7 +69,7 @@ my class Promise {
}
method break(Promise:D: $result) {
- self.keeper.break($result)
+ self.vow.break($result)
}
method !break($result) {
@@ -131,27 +131,27 @@ my class Promise {
# They will be sent to the scheduler when this promise is kept or
# broken.
my $then_promise = Promise.new(:$!scheduler);
- my $k = $then_promise.keeper;
- @!thens.push({ $k.keep(code(self)) });
- @!thens.push(-> $ex { $k.break($ex) });
+ my $vow = $then_promise.vow;
+ @!thens.push({ $vow.keep(code(self)) });
+ @!thens.push(-> $ex { $vow.break($ex) });
$!lock.unlock();
$then_promise
}
}
method start(Promise:U: &code, :$scheduler = $*SCHEDULER) {
- my $p = Promise.new(:$scheduler);
- my $k = $p.keeper;
+ my $p = Promise.new(:$scheduler);
+ my $vow = $p.vow;
$scheduler.schedule_with_catch(
- { $k.keep(code()) },
- -> $ex { $k.break($ex) });
+ { $vow.keep(code()) },
+ -> $ex { $vow.break($ex) });
$p
}
method sleep(Promise:U: $seconds, :$scheduler = $*SCHEDULER) {
- my $p = Promise.new(:$scheduler);
- my $k = $p.keeper;
- $scheduler.schedule_in({ $k.keep(True) }, $seconds);
+ my $p = Promise.new(:$scheduler);
+ my $vow = $p.vow;
+ $scheduler.schedule_in({ $vow.keep(True) }, $seconds);
$p
}
@@ -174,18 +174,18 @@ my class Promise {
Nil;
}
my Mu $c := $AtomicInteger.'constructor/new/(I)V'(nqp::decont($n));
- my $p = Promise.new;
- my $k = $p.keeper;
+ my $p = Promise.new;
+ my $vow = $p.vow;
for @promises -> $cand {
$cand.then({
if .status == Kept {
if $c.'decrementAndGet'() == 0 {
- $k.keep(True)
+ $vow.keep(True)
}
}
else {
if $c.'getAndAdd'(-($n + 1)) > 0 {
- $k.break(.cause)
+ $vow.break(.cause)
}
}
})

0 comments on commit 186b451

Please sign in to comment.
Something went wrong with that request. Please try again.