diff --git a/packages/native-core/src/node.rs b/packages/native-core/src/node.rs index f73e0dc07..fc06862f9 100644 --- a/packages/native-core/src/node.rs +++ b/packages/native-core/src/node.rs @@ -83,3 +83,40 @@ pub enum OwnedAttributeValue { Bool(bool), None, } + +impl OwnedAttributeValue { + pub fn as_text(&self) -> Option<&str> { + match self { + OwnedAttributeValue::Text(text) => Some(text), + _ => None, + } + } + + pub fn as_float(&self) -> Option { + match self { + OwnedAttributeValue::Float(float) => Some(*float), + _ => None, + } + } + + pub fn as_int(&self) -> Option { + match self { + OwnedAttributeValue::Int(int) => Some(*int), + _ => None, + } + } + + pub fn as_bool(&self) -> Option { + match self { + OwnedAttributeValue::Bool(bool) => Some(*bool), + _ => None, + } + } + + pub fn as_none(&self) -> Option<()> { + match self { + OwnedAttributeValue::None => Some(()), + _ => None, + } + } +} diff --git a/packages/native-core/src/worker_pool.rs b/packages/native-core/src/worker_pool.rs index 8b1378917..5ecf377aa 100644 --- a/packages/native-core/src/worker_pool.rs +++ b/packages/native-core/src/worker_pool.rs @@ -1 +1,20 @@ +use crossbeam_deque::{Injector, Stealer, Worker}; +use std::iter; +fn find_task(local: &Worker, global: &Injector, stealers: &[Stealer]) -> Option { + // Pop a task from the local queue, if not empty. + local.pop().or_else(|| { + // Otherwise, we need to look for a task elsewhere. + iter::repeat_with(|| { + // Try stealing a batch of tasks from the global queue. + global + .steal_batch_and_pop(local) + // Or try stealing a task from one of the other threads. + .or_else(|| stealers.iter().map(|s| s.steal()).collect()) + }) + // Loop while no task was stolen and any steal operation needs to be retried. + .find(|s| !s.is_retry()) + // Extract the stolen task, if there is one. + .and_then(|s| s.success()) + }) +}