diff options
Diffstat (limited to 'components/msg/constellation_msg.rs')
-rw-r--r-- | components/msg/constellation_msg.rs | 38 |
1 files changed, 38 insertions, 0 deletions
diff --git a/components/msg/constellation_msg.rs b/components/msg/constellation_msg.rs index 1214b68aa29..f4e7a517673 100644 --- a/components/msg/constellation_msg.rs +++ b/components/msg/constellation_msg.rs @@ -170,6 +170,13 @@ impl PipelineNamespace { index: MessagePortRouterIndex(self.next_index()), } } + + fn next_blob_id(&mut self) -> BlobId { + BlobId { + namespace_id: self.id, + index: BlobIndex(self.next_index()), + } + } } thread_local!(pub static PIPELINE_NAMESPACE: Cell<Option<PipelineNamespace>> = Cell::new(None)); @@ -374,6 +381,37 @@ impl fmt::Display for MessagePortRouterId { } #[derive(Clone, Copy, Debug, Deserialize, Eq, Hash, Ord, PartialEq, PartialOrd, Serialize)] +pub struct BlobIndex(pub NonZeroU32); +malloc_size_of_is_0!(BlobIndex); + +#[derive( + Clone, Copy, Debug, Deserialize, Eq, Hash, MallocSizeOf, Ord, PartialEq, PartialOrd, Serialize, +)] +pub struct BlobId { + pub namespace_id: PipelineNamespaceId, + pub index: BlobIndex, +} + +impl BlobId { + pub fn new() -> BlobId { + PIPELINE_NAMESPACE.with(|tls| { + let mut namespace = tls.get().expect("No namespace set for this thread!"); + let next_blob_id = namespace.next_blob_id(); + tls.set(Some(namespace)); + next_blob_id + }) + } +} + +impl fmt::Display for BlobId { + fn fmt(&self, fmt: &mut fmt::Formatter) -> fmt::Result { + let PipelineNamespaceId(namespace_id) = self.namespace_id; + let BlobIndex(index) = self.index; + write!(fmt, "({},{})", namespace_id, index.get()) + } +} + +#[derive(Clone, Copy, Debug, Deserialize, Eq, Hash, Ord, PartialEq, PartialOrd, Serialize)] pub struct HistoryStateIndex(pub NonZeroU32); malloc_size_of_is_0!(HistoryStateIndex); |