Skip to content

Use a global static variable for IdNamespace counting. #1882

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Oct 20, 2017

Conversation

JerryShih
Copy link
Contributor

@JerryShih JerryShih commented Oct 16, 2017

#1794
Try to use a simple global static variable for that id counting. That's not thread safe. All render-backend should be created in the same thread. If we try to handle the thread problem, I will turn to use thread_local.

cc @sotaroikeda
r? @kvark @glennw


This change is Reviewable

@nical
Copy link
Contributor

nical commented Oct 16, 2017

All render-backend should be created in the same thread.

This is currently not the case. With gecko, each window creates a separate render backend thread, so this code is running on multiple thread.

@nical
Copy link
Contributor

nical commented Oct 16, 2017

Another possibility could be to have some of the bits of the id namespace representing a unique id per webrender instance, and the other bits representing a unique id within the instance (although a global atomic variable is simple enough as well).

@JerryShih
Copy link
Contributor Author

This version try to use a simple global atomic variable for the id counting. 10f7974

@@ -22,6 +22,7 @@ use resource_cache::ResourceCache;
use scene::Scene;
#[cfg(feature = "debugger")]
use serde_json;
use std::sync::atomic::{ATOMIC_USIZE_INIT, AtomicUsize, Ordering};
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The u32is not stable now. Use usize instead.

error: use of unstable library feature 'integer_atomics' (see issue #32976)
--> src\render_backend.rs:25:25
|
25 | use std::sync::atomic::{AtomicU32, Ordering};

@JerryShih
Copy link
Contributor Author

r? @glennw @kvark @nical
10f7974

@sotaroikeda
Copy link
Contributor

We want to avoid to use 0 as id name space. But current patch seems to do it.

@JerryShih
Copy link
Contributor Author

Thanks. If this approach looks good, I will change the init value to 1.

Copy link
Member

@glennw glennw left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

A couple of minor changes, then this looks fine to me, once the other comment is addressed.

@@ -124,6 +125,9 @@ enum DocumentOp {
Rendered(RendererFrame),
}

/// The unique id for WR resource identification.
static mut NEXT_NAMESPACE_ID: AtomicUsize = ATOMIC_USIZE_INIT;
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This doesn't need the mut for an atomic.

let namespace = self.next_namespace_id;
self.next_namespace_id = IdNamespace(namespace.0 + 1);
sender.send(namespace).unwrap();
unsafe {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Once the mut above is removed, the unsafe can also be removed.

@@ -163,6 +166,9 @@ impl RenderBackend {
blob_image_renderer: Option<Box<BlobImageRenderer>>,
enable_render_on_scroll: bool,
) -> RenderBackend {
// The namespace_id should start from 1.
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I can't set the value to 1 directly, so I just increase the value in RenderBackend::new().

error: std::sync::atomic::AtomicUsize::new is not yet stable as a const fn
--> src\render_backend.rs:129:41
|
129 | static NEXT_NAMESPACE_ID: AtomicUsize = AtomicUsize::new(1);
| ^^^^^^^^^^^^^^^^^^^
|
= help: in Nightly builds, add #![feature(const_atomic_usize_new)] to the crate attributes to enable

@JerryShih
Copy link
Contributor Author

@glennw
r? again.

@glennw
Copy link
Member

glennw commented Oct 20, 2017

Looks good, thank you!

@bors-servo r+

@bors-servo
Copy link
Contributor

📌 Commit c551f5f has been approved by glennw

@bors-servo
Copy link
Contributor

⌛ Testing commit c551f5f with merge 56a452d...

bors-servo pushed a commit that referenced this pull request Oct 20, 2017
Use a global static variable for IdNamespace counting.

#1794
Try to use a simple global static variable for that id counting. That's not thread safe. All render-backend should be created in the same thread. If we try to handle the thread problem, I will turn to use thread_local.

cc @sotaroikeda
r? @kvark @glennw

<!-- Reviewable:start -->
---
This change is [<img src="https://reviewable.io/review_button.svg" height="34" align="absmiddle" alt="Reviewable"/>](https://reviewable.io/reviews/servo/webrender/1882)
<!-- Reviewable:end -->
@bors-servo
Copy link
Contributor

☀️ Test successful - status-appveyor, status-travis
Approved by: glennw
Pushing 56a452d to master...

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

5 participants