Now we are using Mutex instead of RwLock, we don't need to be Sync everywhere

This commit is contained in:
Tony Garnock-Jones 2021-07-26 10:53:56 +02:00
parent 73b7ad75bd
commit ff130e9443
3 changed files with 35 additions and 35 deletions

View File

@ -40,7 +40,7 @@ pub type ActorHandle = tokio::task::JoinHandle<ActorResult>;
pub struct Synced;
pub trait Entity<M>: Send + Sync {
pub trait Entity<M>: Send {
fn assert(&mut self, _t: &mut Activation, _a: M, _h: Handle) -> ActorResult {
Ok(())
}
@ -71,7 +71,7 @@ enum CleanupAction {
}
type CleanupActions = Map<Handle, CleanupAction>;
pub type Action = Box<dyn Send + Sync + FnOnce(&mut Activation) -> ActorResult>;
pub type Action = Box<dyn Send + FnOnce(&mut Activation) -> ActorResult>;
pub type PendingEventQueue = Vec<Action>;
// This is what other implementations call a "Turn", renamed here to
@ -138,7 +138,7 @@ pub struct RunningActor {
cleanup_actions: CleanupActions,
next_task_id: u64,
linked_tasks: Map<u64, CancellationToken>,
exit_hooks: Vec<Box<dyn Send + Sync + FnOnce(&mut Activation, &Arc<ActorResult>) -> ActorResult>>,
exit_hooks: Vec<Box<dyn Send + FnOnce(&mut Activation, &Arc<ActorResult>) -> ActorResult>>,
}
pub struct Ref<M> {
@ -274,7 +274,7 @@ impl<'activation> Activation<'activation> {
}
}
pub fn assert<M: 'static + Send + Sync>(&mut self, r: &Arc<Ref<M>>, a: M) -> Handle {
pub fn assert<M: 'static + Send>(&mut self, r: &Arc<Ref<M>>, a: M) -> Handle {
let handle = crate::next_handle();
{
let r = Arc::clone(r);
@ -291,7 +291,7 @@ impl<'activation> Activation<'activation> {
handle
}
pub fn assert_for_myself<M: 'static + Send + Sync>(&mut self, r: &Arc<Ref<M>>, a: M) -> Handle {
pub fn assert_for_myself<M: 'static + Send>(&mut self, r: &Arc<Ref<M>>, a: M) -> Handle {
self.immediate_oid(r);
let handle = crate::next_handle();
{
@ -315,20 +315,20 @@ impl<'activation> Activation<'activation> {
}
}
pub fn message<M: 'static + Send + Sync>(&mut self, r: &Arc<Ref<M>>, m: M) {
pub fn message<M: 'static + Send>(&mut self, r: &Arc<Ref<M>>, m: M) {
let r = Arc::clone(r);
self.pending.queue_for(&r).push(Box::new(
move |t| r.with_entity(|e| e.message(t, m))))
}
pub fn message_for_myself<M: 'static + Send + Sync>(&mut self, r: &Arc<Ref<M>>, m: M) {
pub fn message_for_myself<M: 'static + Send>(&mut self, r: &Arc<Ref<M>>, m: M) {
self.immediate_oid(r);
let r = Arc::clone(r);
self.pending.for_myself.push(Box::new(
move |t| r.with_entity(|e| e.message(t, m))))
}
pub fn sync<M: 'static + Send + Sync>(&mut self, r: &Arc<Ref<M>>, peer: Arc<Ref<Synced>>) {
pub fn sync<M: 'static + Send>(&mut self, r: &Arc<Ref<M>>, peer: Arc<Ref<Synced>>) {
let r = Arc::clone(r);
self.pending.queue_for(&r).push(Box::new(
move |t| r.with_entity(|e| e.sync(t, peer))))
@ -515,7 +515,7 @@ impl Actor {
}
}
pub fn create_and_start<M, E: Entity<M> + Send + Sync + 'static>(
pub fn create_and_start<M, E: Entity<M> + Send + 'static>(
name: tracing::Span,
e: E,
) -> Arc<Ref<M>> {
@ -653,7 +653,7 @@ impl RunningActor {
self.create(InertEntity)
}
pub fn create<M, E: Entity<M> + Send + Sync + 'static>(&mut self, e: E) -> Arc<Ref<M>> {
pub fn create<M, E: Entity<M> + Send + 'static>(&mut self, e: E) -> Arc<Ref<M>> {
let r = self.create_inert();
r.become_entity(e);
r
@ -666,7 +666,7 @@ impl RunningActor {
})
}
pub fn add_exit_hook<M: 'static + Send + Sync>(&mut self, r: &Arc<Ref<M>>) {
pub fn add_exit_hook<M: 'static + Send>(&mut self, r: &Arc<Ref<M>>) {
let r = Arc::clone(r);
self.exit_hooks.push(Box::new(move |t, exit_status| {
r.with_entity(|e| e.exit_hook(t, &exit_status))
@ -802,7 +802,7 @@ impl<M> std::fmt::Debug for Ref<M> {
}
impl Cap {
pub fn guard<M: 'static + Send + Sync>(underlying: &Arc<Ref<M>>) -> Arc<Self>
pub fn guard<M: 'static + Send>(underlying: &Arc<Ref<M>>) -> Arc<Self>
where
for<'a> &'a M: Into<_Any>,
for<'a> M: TryFrom<&'a _Any>,

View File

@ -7,15 +7,15 @@ use std::sync::Arc;
use std::marker::PhantomData;
pub struct During<T>(Map<Handle, DuringRetractionHandler<T>>);
pub type DuringRetractionHandler<T> = Box<dyn Send + Sync + FnOnce(&mut T, &mut Activation) -> ActorResult>;
pub type DuringRetractionHandler<T> = Box<dyn Send + FnOnce(&mut T, &mut Activation) -> ActorResult>;
pub type DuringResult<E> = Result<Option<DuringRetractionHandler<E>>, Error>;
pub struct DuringEntity<M, E, Fa, Fm>
where
M: 'static + Send + Sync,
E: 'static + Send + Sync,
Fa: 'static + Send + Sync + FnMut(&mut E, &mut Activation, M) -> DuringResult<E>,
Fm: 'static + Send + Sync + FnMut(&mut E, &mut Activation, M) -> ActorResult,
M: 'static + Send,
E: 'static + Send,
Fa: 'static + Send + FnMut(&mut E, &mut Activation, M) -> DuringResult<E>,
Fm: 'static + Send + FnMut(&mut E, &mut Activation, M) -> ActorResult,
{
state: E,
assertion_handler: Option<Fa>,
@ -29,7 +29,7 @@ impl<T> During<T> {
During(Map::new())
}
pub fn await_retraction<F: 'static + Send + Sync + FnOnce(&mut T, &mut Activation) -> ActorResult>(
pub fn await_retraction<F: 'static + Send + FnOnce(&mut T, &mut Activation) -> ActorResult>(
&mut self,
h: Handle,
f: F,
@ -43,24 +43,24 @@ impl<T> During<T> {
}
}
pub fn entity<M: 'static + Send + Sync, E>(
pub fn entity<M: 'static + Send, E>(
state: E
) -> DuringEntity<M,
E,
fn (&mut E, &mut Activation, M) -> DuringResult<E>,
fn (&mut E, &mut Activation, M) -> ActorResult>
where
E: 'static + Send + Sync,
E: 'static + Send,
{
DuringEntity::new(state, None, None)
}
impl<M, E, Fa, Fm> DuringEntity<M, E, Fa, Fm>
where
M: 'static + Send + Sync,
E: 'static + Send + Sync,
Fa: 'static + Send + Sync + FnMut(&mut E, &mut Activation, M) -> DuringResult<E>,
Fm: 'static + Send + Sync + FnMut(&mut E, &mut Activation, M) -> ActorResult,
M: 'static + Send,
E: 'static + Send,
Fa: 'static + Send + FnMut(&mut E, &mut Activation, M) -> DuringResult<E>,
Fm: 'static + Send + FnMut(&mut E, &mut Activation, M) -> ActorResult,
{
pub fn new(state: E, assertion_handler: Option<Fa>, message_handler: Option<Fm>) -> Self {
DuringEntity {
@ -74,7 +74,7 @@ where
pub fn on_asserted<Fa1>(self, assertion_handler: Fa1) -> DuringEntity<M, E, Fa1, Fm>
where
Fa1: 'static + Send + Sync + FnMut(&mut E, &mut Activation, M) -> DuringResult<E>,
Fa1: 'static + Send + FnMut(&mut E, &mut Activation, M) -> DuringResult<E>,
{
DuringEntity {
state: self.state,
@ -87,7 +87,7 @@ where
pub fn on_message<Fm1>(self, message_handler: Fm1) -> DuringEntity<M, E, Fa, Fm1>
where
Fm1: 'static + Send + Sync + FnMut(&mut E, &mut Activation, M) -> ActorResult,
Fm1: 'static + Send + FnMut(&mut E, &mut Activation, M) -> ActorResult,
{
DuringEntity {
state: self.state,
@ -105,9 +105,9 @@ where
impl<E, Fa, Fm> DuringEntity<_Any, E, Fa, Fm>
where
E: 'static + Send + Sync,
Fa: 'static + Send + Sync + FnMut(&mut E, &mut Activation, _Any) -> DuringResult<E>,
Fm: 'static + Send + Sync + FnMut(&mut E, &mut Activation, _Any) -> ActorResult,
E: 'static + Send,
Fa: 'static + Send + FnMut(&mut E, &mut Activation, _Any) -> DuringResult<E>,
Fm: 'static + Send + FnMut(&mut E, &mut Activation, _Any) -> ActorResult,
{
pub fn create_cap(self, ac: &mut RunningActor) -> Arc<Cap>
{
@ -117,10 +117,10 @@ where
impl<M, E, Fa, Fm> Entity<M> for DuringEntity<M, E, Fa, Fm>
where
M: Send + Sync,
E: 'static + Send + Sync,
Fa: 'static + Send + Sync + FnMut(&mut E, &mut Activation, M) -> DuringResult<E>,
Fm: 'static + Send + Sync + FnMut(&mut E, &mut Activation, M) -> ActorResult,
M: Send,
E: 'static + Send,
Fa: 'static + Send + FnMut(&mut E, &mut Activation, M) -> DuringResult<E>,
Fm: 'static + Send + FnMut(&mut E, &mut Activation, M) -> ActorResult,
{
fn assert(&mut self, t: &mut Activation, a: M, h: Handle) -> ActorResult {
match &mut self.assertion_handler {

View File

@ -153,8 +153,8 @@ pub fn connect_stream<I, O, E, F>(
) where
I: 'static + Send + AsyncRead,
O: 'static + Send + AsyncWrite,
E: 'static + Send + std::marker::Sync,
F: 'static + Send + std::marker::Sync + FnMut(&mut E, &mut Activation, Arc<Cap>) -> during::DuringResult<E>
E: 'static + Send,
F: 'static + Send + FnMut(&mut E, &mut Activation, Arc<Cap>) -> during::DuringResult<E>
{
let i = Input::Bytes(Box::pin(i));
let o = Output::Bytes(Box::pin(o));