diff options
author | bors-servo <lbergstrom+bors@mozilla.com> | 2019-12-19 16:16:56 -0500 |
---|---|---|
committer | GitHub <noreply@github.com> | 2019-12-19 16:16:56 -0500 |
commit | bac9903fbeed0a394a86c0091e727aada665433d (patch) | |
tree | 15f61a4fdcc8bbcc09f10a39e25495fb49cb9a75 /components/msg | |
parent | aa36d5f657eb32b59d994d08b177a02372b4b01c (diff) | |
parent | 6e8a85482c2068d4dbccb992954271f725570f91 (diff) | |
download | servo-bac9903fbeed0a394a86c0091e727aada665433d.tar.gz servo-bac9903fbeed0a394a86c0091e727aada665433d.zip |
Auto merge of #24123 - gterzian:redo_blob, r=jdm
Restructure Blob, structured serialization
<!-- Please describe your changes on the following line: -->
FIX #24052 and also address the "cloning" half of FIX #23917
---
<!-- Thank you for contributing to Servo! Please replace each `[ ]` by `[X]` when the step is complete, and replace `___` with appropriate data: -->
- [ ] `./mach build -d` does not report any errors
- [ ] `./mach test-tidy` does not report any errors
- [ ] These changes fix #___ (GitHub issue number if applicable)
<!-- Either: -->
- [ ] There are tests for these changes OR
- [ ] These changes do not require tests because ___
<!-- Also, please make sure that "Allow edits from maintainers" checkbox is checked, so that we can help you if you get stuck somewhere along the way.-->
<!-- Pull requests that do not address these steps are welcome, but they will require additional verification as part of the review process. -->
<!-- Reviewable:start -->
---
This change is [<img src="https://reviewable.io/review_button.svg" height="34" align="absmiddle" alt="Reviewable"/>](https://reviewable.io/reviews/servo/servo/24123)
<!-- Reviewable:end -->
Diffstat (limited to 'components/msg')
-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); |