clear/deliver -> rollback/commit, and don't commit on drop

This commit is contained in:
Tony Garnock-Jones 2022-02-02 12:10:13 +01:00
parent d7a847de37
commit 1244e416d0
2 changed files with 16 additions and 28 deletions

View File

@ -572,8 +572,8 @@ impl From<ActorResult> for RunDisposition {
impl FacetRef { impl FacetRef {
/// Executes `f` in a new "[turn][Activation]" for `actor`. If `f` returns `Ok(())`, /// Executes `f` in a new "[turn][Activation]" for `actor`. If `f` returns `Ok(())`,
/// [commits the turn][Activation::deliver] and performs the buffered actions; otherwise, /// [commits the turn][Activation::commit] and performs the buffered actions; otherwise,
/// [abandons the turn][Activation::clear] and discards the buffered actions. /// [abandons the turn][Activation::rollback] and discards the buffered actions.
/// ///
/// Returns `true` if, at the end of the activation, `actor` had not yet terminated. /// Returns `true` if, at the end of the activation, `actor` had not yet terminated.
/// ///
@ -592,7 +592,7 @@ impl FacetRef {
/// Executes `f` in a new "[turn][Activation]" for `actor`. If `f` returns /// Executes `f` in a new "[turn][Activation]" for `actor`. If `f` returns
/// `Some(exit_status)`, terminates `actor` with that `exit_status`. Otherwise, if `f` /// `Some(exit_status)`, terminates `actor` with that `exit_status`. Otherwise, if `f`
/// returns `None`, leaves `actor` in runnable state. [Commits buffered /// returns `None`, leaves `actor` in runnable state. [Commits buffered
/// actions][Activation::deliver] unless `actor` terminates with an `Err` status. /// actions][Activation::commit] unless `actor` terminates with an `Err` status.
/// ///
/// Returns `true` if, at the end of the activation, `actor` had not yet terminated. /// Returns `true` if, at the end of the activation, `actor` had not yet terminated.
/// ///
@ -619,12 +619,15 @@ impl FacetRef {
state); state);
let f_result = f(&mut activation); let f_result = f(&mut activation);
let is_alive = match activation.restore_invariants(f_result) { let is_alive = match activation.restore_invariants(f_result) {
RunDisposition::Continue => true, RunDisposition::Continue => {
activation.commit();
true
}
RunDisposition::Terminate(exit_status) => { RunDisposition::Terminate(exit_status) => {
if exit_status.is_err() { match exit_status {
activation.clear(); Err(_) => activation.rollback(),
Ok(()) => activation.commit(),
} }
drop(activation);
let exit_status = Arc::new(exit_status); let exit_status = Arc::new(exit_status);
state.cleanup(&self.actor, state.cleanup(&self.actor,
&exit_status, &exit_status,
@ -967,23 +970,20 @@ impl<'activation> Activation<'activation> {
} }
/// Discards all pending actions in this activation. /// Discards all pending actions in this activation.
pub fn clear(&mut self) { pub fn rollback(self) {
self.pending.clear(); // Nothing to do
} }
/// Delivers all pending actions in this activation. /// Delivers all pending actions in this activation.
/// ///
/// This is called automatically when an `Activation` is
/// `Drop`ped.
///
/// # Panics /// # Panics
/// ///
/// Panics if any pending "`final_actions`" or actions "`for_myself`" (resulting from /// Panics if any pending "`final_actions`" or actions "`for_myself`" (resulting from
/// [`assert_for_myself`][Self::assert_for_myself] or /// [`assert_for_myself`][Self::assert_for_myself] or
/// [`message_for_myself`][Self::message_for_myself]) are outstanding at the time of the /// [`message_for_myself`][Self::message_for_myself]) are outstanding at the time of the
/// call. /// call.
pub fn deliver(&mut self) { pub fn commit(&mut self) {
self.pending.deliver(); self.pending.commit();
} }
/// Construct an entity with behaviour [`InertEntity`] within the active facet. /// Construct an entity with behaviour [`InertEntity`] within the active facet.
@ -1540,13 +1540,7 @@ impl EventBuffer {
.or_insert((mailbox.tx.clone(), Vec::new())).1 .or_insert((mailbox.tx.clone(), Vec::new())).1
} }
fn clear(&mut self) { fn commit(&mut self) {
self.queues = HashMap::new();
self.for_myself = PendingEventQueue::new();
self.final_actions = Vec::new();
}
fn deliver(&mut self) {
tracing::trace!("EventBuffer::deliver"); tracing::trace!("EventBuffer::deliver");
if !self.final_actions.is_empty() { if !self.final_actions.is_empty() {
panic!("Unprocessed final_actions at deliver() time"); panic!("Unprocessed final_actions at deliver() time");
@ -1604,12 +1598,6 @@ impl EventBuffer {
} }
} }
impl Drop for EventBuffer {
fn drop(&mut self) {
self.deliver()
}
}
impl Account { impl Account {
/// Construct a new `Account`, storing `name` within it for /// Construct a new `Account`, storing `name` within it for
/// debugging use. /// debugging use.

View File

@ -404,7 +404,7 @@ impl TunnelRelay {
} }
} }
} }
t.deliver(); t.commit();
Ok(()) Ok(())
} }
} }