mirror of
https://github.com/servo/servo.git
synced 2025-08-04 13:10:20 +01:00
Make Task require Send
This commit is contained in:
parent
8000efac75
commit
f088b708c9
10 changed files with 25 additions and 21 deletions
|
@ -122,7 +122,7 @@ impl TrustedPromise {
|
||||||
|
|
||||||
/// A task which will reject the promise.
|
/// A task which will reject the promise.
|
||||||
#[allow(unrooted_must_root)]
|
#[allow(unrooted_must_root)]
|
||||||
pub fn reject_task(self, error: Error) -> impl Send + Task {
|
pub fn reject_task(self, error: Error) -> impl Task {
|
||||||
let this = self;
|
let this = self;
|
||||||
task!(reject_promise: move || {
|
task!(reject_promise: move || {
|
||||||
debug!("Rejecting promise.");
|
debug!("Rejecting promise.");
|
||||||
|
@ -135,7 +135,7 @@ impl TrustedPromise {
|
||||||
|
|
||||||
/// A task which will resolve the promise.
|
/// A task which will resolve the promise.
|
||||||
#[allow(unrooted_must_root)]
|
#[allow(unrooted_must_root)]
|
||||||
pub fn resolve_task<T>(self, value: T) -> impl Send + Task
|
pub fn resolve_task<T>(self, value: T) -> impl Task
|
||||||
where
|
where
|
||||||
T: ToJSValConvertible + Send,
|
T: ToJSValConvertible + Send,
|
||||||
{
|
{
|
||||||
|
|
|
@ -645,8 +645,9 @@ impl WorkletThread {
|
||||||
}
|
}
|
||||||
|
|
||||||
/// Run a task in the main script thread.
|
/// Run a task in the main script thread.
|
||||||
fn run_in_script_thread<T>(&self, task: T) where
|
fn run_in_script_thread<T>(&self, task: T)
|
||||||
T: 'static + Send + Task,
|
where
|
||||||
|
T: Task + 'static,
|
||||||
{
|
{
|
||||||
let msg = CommonScriptMsg::Task(ScriptThreadEventCategory::WorkletEvent, box task);
|
let msg = CommonScriptMsg::Task(ScriptThreadEventCategory::WorkletEvent, box task);
|
||||||
let msg = MainThreadScriptMsg::Common(msg);
|
let msg = MainThreadScriptMsg::Common(msg);
|
||||||
|
|
|
@ -44,7 +44,7 @@ pub enum CommonScriptMsg {
|
||||||
/// supplied channel.
|
/// supplied channel.
|
||||||
CollectReports(ReportsChan),
|
CollectReports(ReportsChan),
|
||||||
/// Generic message that encapsulates event handling.
|
/// Generic message that encapsulates event handling.
|
||||||
Task(ScriptThreadEventCategory, Box<Task + Send>),
|
Task(ScriptThreadEventCategory, Box<Task>),
|
||||||
}
|
}
|
||||||
|
|
||||||
impl fmt::Debug for CommonScriptMsg {
|
impl fmt::Debug for CommonScriptMsg {
|
||||||
|
|
|
@ -15,7 +15,7 @@ macro_rules! task {
|
||||||
struct $name<F>(F);
|
struct $name<F>(F);
|
||||||
impl<F> ::task::Task for $name<F>
|
impl<F> ::task::Task for $name<F>
|
||||||
where
|
where
|
||||||
F: ::std::ops::FnOnce(),
|
F: ::std::ops::FnOnce() + Send,
|
||||||
{
|
{
|
||||||
fn name(&self) -> &'static str {
|
fn name(&self) -> &'static str {
|
||||||
stringify!($name)
|
stringify!($name)
|
||||||
|
@ -30,13 +30,13 @@ macro_rules! task {
|
||||||
}
|
}
|
||||||
|
|
||||||
/// A task that can be run. The name method is for profiling purposes.
|
/// A task that can be run. The name method is for profiling purposes.
|
||||||
pub trait Task {
|
pub trait Task: Send {
|
||||||
#[allow(unsafe_code)]
|
#[allow(unsafe_code)]
|
||||||
fn name(&self) -> &'static str { unsafe { intrinsics::type_name::<Self>() } }
|
fn name(&self) -> &'static str { unsafe { intrinsics::type_name::<Self>() } }
|
||||||
fn run(self: Box<Self>);
|
fn run(self: Box<Self>);
|
||||||
}
|
}
|
||||||
|
|
||||||
impl fmt::Debug for Task + Send {
|
impl fmt::Debug for Task {
|
||||||
fn fmt(&self, fmt: &mut fmt::Formatter) -> fmt::Result {
|
fn fmt(&self, fmt: &mut fmt::Formatter) -> fmt::Result {
|
||||||
fmt.debug_tuple(self.name()).field(&format_args!("...")).finish()
|
fmt.debug_tuple(self.name()).field(&format_args!("...")).finish()
|
||||||
}
|
}
|
||||||
|
@ -50,9 +50,9 @@ pub struct TaskCanceller {
|
||||||
impl TaskCanceller {
|
impl TaskCanceller {
|
||||||
/// Returns a wrapped `task` that will be cancelled if the `TaskCanceller`
|
/// Returns a wrapped `task` that will be cancelled if the `TaskCanceller`
|
||||||
/// says so.
|
/// says so.
|
||||||
pub fn wrap_task<T>(&self, task: Box<T>) -> Box<Task + Send>
|
pub fn wrap_task<T>(&self, task: Box<T>) -> Box<Task>
|
||||||
where
|
where
|
||||||
T: Send + Task + 'static,
|
T: Task + 'static,
|
||||||
{
|
{
|
||||||
box CancellableTask {
|
box CancellableTask {
|
||||||
cancelled: self.cancelled.clone(),
|
cancelled: self.cancelled.clone(),
|
||||||
|
@ -62,14 +62,14 @@ impl TaskCanceller {
|
||||||
}
|
}
|
||||||
|
|
||||||
/// A task that can be cancelled by toggling a shared flag.
|
/// A task that can be cancelled by toggling a shared flag.
|
||||||
pub struct CancellableTask<T: Send + Task> {
|
pub struct CancellableTask<T: Task> {
|
||||||
cancelled: Option<Arc<AtomicBool>>,
|
cancelled: Option<Arc<AtomicBool>>,
|
||||||
inner: Box<T>,
|
inner: Box<T>,
|
||||||
}
|
}
|
||||||
|
|
||||||
impl<T> CancellableTask<T>
|
impl<T> CancellableTask<T>
|
||||||
where
|
where
|
||||||
T: Send + Task,
|
T: Task,
|
||||||
{
|
{
|
||||||
fn is_cancelled(&self) -> bool {
|
fn is_cancelled(&self) -> bool {
|
||||||
self.cancelled.as_ref().map_or(false, |cancelled| {
|
self.cancelled.as_ref().map_or(false, |cancelled| {
|
||||||
|
@ -80,7 +80,7 @@ where
|
||||||
|
|
||||||
impl<T> Task for CancellableTask<T>
|
impl<T> Task for CancellableTask<T>
|
||||||
where
|
where
|
||||||
T: Send + Task,
|
T: Task,
|
||||||
{
|
{
|
||||||
fn name(&self) -> &'static str {
|
fn name(&self) -> &'static str {
|
||||||
self.inner.name()
|
self.inner.name()
|
||||||
|
|
|
@ -32,7 +32,7 @@ impl TaskSource for DOMManipulationTaskSource {
|
||||||
canceller: &TaskCanceller,
|
canceller: &TaskCanceller,
|
||||||
) -> Result<(), ()>
|
) -> Result<(), ()>
|
||||||
where
|
where
|
||||||
T: Task + Send + 'static,
|
T: Task + 'static,
|
||||||
{
|
{
|
||||||
let msg = MainThreadScriptMsg::Common(CommonScriptMsg::Task(
|
let msg = MainThreadScriptMsg::Common(CommonScriptMsg::Task(
|
||||||
ScriptThreadEventCategory::ScriptEvent,
|
ScriptThreadEventCategory::ScriptEvent,
|
||||||
|
|
|
@ -25,7 +25,7 @@ impl TaskSource for FileReadingTaskSource {
|
||||||
canceller: &TaskCanceller,
|
canceller: &TaskCanceller,
|
||||||
) -> Result<(), ()>
|
) -> Result<(), ()>
|
||||||
where
|
where
|
||||||
T: Send + Task + 'static,
|
T: Task + 'static,
|
||||||
{
|
{
|
||||||
self.0.send(CommonScriptMsg::Task(
|
self.0.send(CommonScriptMsg::Task(
|
||||||
ScriptThreadEventCategory::FileRead,
|
ScriptThreadEventCategory::FileRead,
|
||||||
|
|
|
@ -20,9 +20,12 @@ pub trait TaskSource {
|
||||||
canceller: &TaskCanceller,
|
canceller: &TaskCanceller,
|
||||||
) -> Result<(), ()>
|
) -> Result<(), ()>
|
||||||
where
|
where
|
||||||
T: Send + Task + 'static;
|
T: Task + 'static;
|
||||||
|
|
||||||
fn queue<T: Task + Send + 'static>(&self, msg: Box<T>, global: &GlobalScope) -> Result<(), ()> {
|
fn queue<T>(&self, msg: Box<T>, global: &GlobalScope) -> Result<(), ()>
|
||||||
|
where
|
||||||
|
T: Task + 'static,
|
||||||
|
{
|
||||||
self.queue_with_canceller(msg, &global.task_canceller())
|
self.queue_with_canceller(msg, &global.task_canceller())
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -22,7 +22,7 @@ impl TaskSource for NetworkingTaskSource {
|
||||||
canceller: &TaskCanceller,
|
canceller: &TaskCanceller,
|
||||||
) -> Result<(), ()>
|
) -> Result<(), ()>
|
||||||
where
|
where
|
||||||
T: Send + Task + 'static,
|
T: Task + 'static,
|
||||||
{
|
{
|
||||||
self.0.send(CommonScriptMsg::Task(
|
self.0.send(CommonScriptMsg::Task(
|
||||||
ScriptThreadEventCategory::NetworkEvent,
|
ScriptThreadEventCategory::NetworkEvent,
|
||||||
|
@ -36,7 +36,7 @@ impl NetworkingTaskSource {
|
||||||
/// global scope gets destroyed.
|
/// global scope gets destroyed.
|
||||||
pub fn queue_unconditionally<T>(&self, msg: Box<T>) -> Result<(), ()>
|
pub fn queue_unconditionally<T>(&self, msg: Box<T>) -> Result<(), ()>
|
||||||
where
|
where
|
||||||
T: Task + Send + 'static,
|
T: Task + 'static,
|
||||||
{
|
{
|
||||||
self.0.send(CommonScriptMsg::Task(ScriptThreadEventCategory::NetworkEvent, msg))
|
self.0.send(CommonScriptMsg::Task(ScriptThreadEventCategory::NetworkEvent, msg))
|
||||||
}
|
}
|
||||||
|
|
|
@ -36,7 +36,7 @@ impl TaskSource for PerformanceTimelineTaskSource {
|
||||||
canceller: &TaskCanceller,
|
canceller: &TaskCanceller,
|
||||||
) -> Result<(), ()>
|
) -> Result<(), ()>
|
||||||
where
|
where
|
||||||
T: Send + Task + 'static,
|
T: Task + 'static,
|
||||||
{
|
{
|
||||||
let msg = CommonScriptMsg::Task(
|
let msg = CommonScriptMsg::Task(
|
||||||
ScriptThreadEventCategory::PerformanceTimelineTask,
|
ScriptThreadEventCategory::PerformanceTimelineTask,
|
||||||
|
|
|
@ -32,7 +32,7 @@ impl TaskSource for UserInteractionTaskSource {
|
||||||
canceller: &TaskCanceller,
|
canceller: &TaskCanceller,
|
||||||
) -> Result<(), ()>
|
) -> Result<(), ()>
|
||||||
where
|
where
|
||||||
T: Task + Send + 'static,
|
T: Task + 'static,
|
||||||
{
|
{
|
||||||
let msg = MainThreadScriptMsg::Common(CommonScriptMsg::Task(
|
let msg = MainThreadScriptMsg::Common(CommonScriptMsg::Task(
|
||||||
ScriptThreadEventCategory::InputEvent,
|
ScriptThreadEventCategory::InputEvent,
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue