Skip to content
Snippets Groups Projects
Commit 875a17f0 authored by Russel Arbore's avatar Russel Arbore
Browse files

Just add the type I want...

parent 6f997c94
No related branches found
No related tags found
1 merge request!193Fix parallel code gen in RT backend
Pipeline #201789 failed
This commit is part of merge request !193. Comments created here will be created in the context of that merge request.
...@@ -594,7 +594,7 @@ impl<'a> RTContext<'a> { ...@@ -594,7 +594,7 @@ impl<'a> RTContext<'a> {
(_, true) => { (_, true) => {
write!(block, "{}", self.clone_arc(id).unwrap())?; write!(block, "{}", self.clone_arc(id).unwrap())?;
format!( format!(
"*async_call_{}.lock().await = Some(::async_std::task::spawn(async move {{ ", "*async_call_{}.lock().await = ::hercules_rt::__FutureSlotWrapper::new(::async_std::task::spawn(async move {{ ",
id.idx(), id.idx(),
) )
} }
...@@ -1106,7 +1106,7 @@ impl<'a> RTContext<'a> { ...@@ -1106,7 +1106,7 @@ impl<'a> RTContext<'a> {
if is_async_call { if is_async_call {
write!( write!(
w, w,
"let mut async_call_{} = ::std::sync::Arc::new(::async_std::sync::Mutex::new(None));", "let mut async_call_{} = ::std::sync::Arc::new(::async_std::sync::Mutex::new(::hercules_rt::__FutureSlotWrapper::empty()));",
idx, idx,
)?; )?;
} else { } else {
...@@ -1382,10 +1382,7 @@ impl<'a> RTContext<'a> { ...@@ -1382,10 +1382,7 @@ impl<'a> RTContext<'a> {
&& func.schedules[id.idx()].contains(&Schedule::AsyncCall) && func.schedules[id.idx()].contains(&Schedule::AsyncCall)
{ {
assert!(!lhs); assert!(!lhs);
format!( format!("async_call_{}.lock().await.inspect().await", id.idx(),)
"async_call_{}.lock().await.as_mut().unwrap().await",
id.idx(),
)
} else { } else {
format!("node_{}", id.idx()) format!("node_{}", id.idx())
} }
......
#![feature(once_cell_try)] #![feature(once_cell_try)]
use std::alloc::{alloc, dealloc, GlobalAlloc, Layout, System}; use std::alloc::{alloc, dealloc, GlobalAlloc, Layout, System};
use std::future::Future;
use std::marker::PhantomData; use std::marker::PhantomData;
use std::ptr::{copy_nonoverlapping, write_bytes, NonNull}; use std::ptr::{copy_nonoverlapping, write_bytes, NonNull};
use std::slice::{from_raw_parts, from_raw_parts_mut}; use std::slice::{from_raw_parts, from_raw_parts_mut};
use std::sync::OnceLock; use std::sync::OnceLock;
/* /*
...@@ -426,6 +426,46 @@ impl __RawPtrSendSync { ...@@ -426,6 +426,46 @@ impl __RawPtrSendSync {
unsafe impl Send for __RawPtrSendSync {} unsafe impl Send for __RawPtrSendSync {}
unsafe impl Sync for __RawPtrSendSync {} unsafe impl Sync for __RawPtrSendSync {}
#[derive(Clone, Debug)]
pub struct __FutureSlotWrapper<T, F>
where
T: Copy,
F: Future<Output = T>,
{
future: Option<F>,
slot: Option<T>,
}
impl<T, F> __FutureSlotWrapper<T, F>
where
T: Copy,
F: Future<Output = T>,
{
pub fn empty() -> Self {
Self {
future: None,
slot: None,
}
}
pub fn new(f: F) -> Self {
Self {
future: Some(f),
slot: None,
}
}
pub async fn inspect(&mut self) -> T {
if let Some(slot) = self.slot {
slot
} else {
let result = self.future.take().unwrap().await;
self.slot = Some(result);
result
}
}
}
/* /*
* A HerculesBox holds memory that can be on any device and provides a common interface to moving * A HerculesBox holds memory that can be on any device and provides a common interface to moving
* data where it is needed. * data where it is needed.
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment