parallel_processor/execution_manager/
executor_address.rs1use crate::execution_manager::execution_context::ExecutorDropper;
2use std::any::{Any, TypeId};
3use std::fmt::{Debug, Formatter};
4use std::hash::{Hash, Hasher};
5use std::sync::Arc;
6
7#[derive(Clone)]
8pub struct ExecutorAddress {
9 pub(crate) executor_keeper: Arc<ExecutorDropper>,
10 pub(crate) init_data: Arc<dyn Any + Sync + Send + 'static>,
11 pub(crate) executor_type_id: TypeId,
12 pub(crate) executor_internal_id: u64,
13}
14unsafe impl Send for ExecutorAddress {}
15unsafe impl Sync for ExecutorAddress {}
16
17impl ExecutorAddress {
18 pub fn is_of_type<T: 'static>(&self) -> bool {
19 self.executor_type_id == TypeId::of::<T>()
20 }
21
22 pub fn to_weak(&self) -> WeakExecutorAddress {
23 WeakExecutorAddress {
24 executor_type_id: self.executor_type_id,
25 executor_internal_id: self.executor_internal_id,
26 }
27 }
28}
29
30impl Hash for ExecutorAddress {
31 fn hash<H: Hasher>(&self, state: &mut H) {
32 self.executor_type_id.hash(state);
33 state.write_u64(self.executor_internal_id);
34 }
35}
36impl PartialEq for ExecutorAddress {
37 #[inline(always)]
38 fn eq(&self, other: &Self) -> bool {
39 (self.executor_type_id, self.executor_internal_id)
40 .eq(&(other.executor_type_id, other.executor_internal_id))
41 }
42}
43impl Eq for ExecutorAddress {}
44
45#[derive(Copy, Clone)]
46pub struct WeakExecutorAddress {
47 pub(crate) executor_type_id: TypeId,
48 pub(crate) executor_internal_id: u64,
49}
50
51impl Debug for WeakExecutorAddress {
52 fn fmt(&self, f: &mut Formatter<'_>) -> std::fmt::Result {
53 f.write_fmt(format_args!(
54 "({:?},I{})",
55 self.executor_type_id, self.executor_internal_id,
56 ))
57 }
58}
59
60impl WeakExecutorAddress {
61 pub(crate) fn empty() -> Self {
62 Self {
63 executor_type_id: TypeId::of::<()>(),
64 executor_internal_id: 0,
65 }
66 }
67}
68
69impl Hash for WeakExecutorAddress {
70 fn hash<H: Hasher>(&self, state: &mut H) {
71 self.executor_type_id.hash(state);
72 state.write_u64(self.executor_internal_id);
73 }
74}
75impl PartialEq for WeakExecutorAddress {
76 #[inline(always)]
77 fn eq(&self, other: &Self) -> bool {
78 (self.executor_type_id, self.executor_internal_id)
79 .eq(&(other.executor_type_id, other.executor_internal_id))
80 }
81}
82impl Eq for WeakExecutorAddress {}