mirror of
https://github.com/servo/servo.git
synced 2025-07-22 23:03:42 +01:00
Prevent moving CanGc values between threads/tasks (#33902)
* Make CanGc non-sendable, and add documentation. Signed-off-by: Josh Matthews <josh@joshmatthews.net> * Update CanGc usage to fix usages that were moved between threads/tasks. Signed-off-by: Josh Matthews <josh@joshmatthews.net> --------- Signed-off-by: Josh Matthews <josh@joshmatthews.net>
This commit is contained in:
parent
a58da5aa83
commit
b85093ad74
10 changed files with 69 additions and 89 deletions
|
@ -1115,10 +1115,17 @@ impl Runnable {
|
|||
}
|
||||
|
||||
#[derive(Clone, Copy, Debug)]
|
||||
pub struct CanGc(());
|
||||
/// A compile-time marker that there are operations that could trigger a JS garbage collection
|
||||
/// operation within the current stack frame. It is trivially copyable, so it should be passed
|
||||
/// as a function argument and reused when calling other functions whenever possible. Since it
|
||||
/// is only meaningful within the current stack frame, it is impossible to move it to a different
|
||||
/// thread or into a task that will execute asynchronously.
|
||||
pub struct CanGc(std::marker::PhantomData<*mut ()>);
|
||||
|
||||
impl CanGc {
|
||||
/// Create a new CanGc value, representing that a GC operation is possible within the
|
||||
/// current stack frame.
|
||||
pub fn note() -> CanGc {
|
||||
CanGc(())
|
||||
CanGc(std::marker::PhantomData)
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue