Skip to content

Commit d4ddf18

Browse files
author
Lucas Paixão
committed
Possibility to change the stack size and code fix
1 parent 33e3326 commit d4ddf18

File tree

11 files changed

+192
-108
lines changed

11 files changed

+192
-108
lines changed

src/buf/fixed/handle.rs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@ use std::cell::RefCell;
66
use libc::iovec;
77
use std::fmt::{self, Debug};
88
use std::ops::{Deref, DerefMut};
9-
use std::rc::Rc;
9+
use std::sync::Arc;
1010

1111
// Data to construct a `FixedBuf` handle from.
1212
pub(crate) struct CheckedOutBuf {
@@ -32,7 +32,7 @@ pub(crate) struct CheckedOutBuf {
3232
/// [`FixedBufPool`]: super::FixedBufPool
3333
///
3434
pub struct FixedBuf {
35-
registry: Rc<RefCell<dyn FixedBuffers>>,
35+
registry: Arc<RefCell<dyn FixedBuffers>>,
3636
buf: CheckedOutBuf,
3737
}
3838

@@ -57,7 +57,7 @@ impl FixedBuf {
5757
// - the array will not be deallocated until the buffer is checked in;
5858
// - the data in the array must be initialized up to the number of bytes
5959
// given in init_len.
60-
pub(super) unsafe fn new(registry: Rc<RefCell<dyn FixedBuffers>>, buf: CheckedOutBuf) -> Self {
60+
pub(super) unsafe fn new(registry: Arc<RefCell<dyn FixedBuffers>>, buf: CheckedOutBuf) -> Self {
6161
FixedBuf { registry, buf }
6262
}
6363

src/buf/fixed/pool.rs

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,6 @@ use crate::buf::fixed::handle::CheckedOutBuf;
1616
use crate::buf::fixed::plumbing::Pool;
1717
use crate::buf::fixed::shared::{process, register, unregister};
1818
use std::io;
19-
use std::rc::Rc;
2019
use std::sync::Arc;
2120
use tokio::pin;
2221
use tokio::sync::Notify;
@@ -95,7 +94,7 @@ use tokio::sync::Notify;
9594
/// ```
9695
#[derive(Clone)]
9796
pub struct FixedBufPool<T: IoBufMut> {
98-
inner: RefCell<Rc<RefCell<plumbing::Pool<T>>>>,
97+
inner: RefCell<Arc<RefCell<plumbing::Pool<T>>>>,
9998
}
10099

101100
impl<T: IoBufMut> FixedBufPool<T> {
@@ -164,7 +163,7 @@ impl<T: IoBufMut> FixedBufPool<T> {
164163
/// ```
165164
pub fn new(bufs: impl IntoIterator<Item = T>) -> Self {
166165
FixedBufPool {
167-
inner: RefCell::new(Rc::new(RefCell::new(Pool::new(bufs.into_iter())))),
166+
inner: RefCell::new(Arc::new(RefCell::new(Pool::new(bufs.into_iter())))),
168167
}
169168
}
170169

@@ -258,7 +257,7 @@ impl<T: IoBufMut> FixedBufPool<T> {
258257
self.next_when_notified(cap, notify).await
259258
}
260259

261-
fn get_fixed_buf(inner: Rc<RefCell<Pool<T>>>, data: CheckedOutBuf) -> FixedBuf {
260+
fn get_fixed_buf(inner: Arc<RefCell<Pool<T>>>, data: CheckedOutBuf) -> FixedBuf {
262261
// Safety: the validity of buffer data is ensured by
263262
// plumbing::Pool::try_next
264263
unsafe { FixedBuf::new(inner, data) }

src/buf/fixed/registry.rs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@ use std::cell::RefCell;
55
use crate::buf::fixed::shared::{process, register, unregister};
66
use crate::buf::IoBufMut;
77
use std::io;
8-
use std::rc::Rc;
8+
use std::sync::Arc;
99

1010
/// An indexed collection of I/O buffers pre-registered with the kernel.
1111
///
@@ -31,7 +31,7 @@ use std::rc::Rc;
3131
/// [`Runtime`]: crate::Runtime
3232
#[derive(Clone)]
3333
pub struct FixedBufRegistry<T: IoBufMut> {
34-
inner: RefCell<Rc<RefCell<plumbing::Registry<T>>>>,
34+
inner: RefCell<Arc<RefCell<plumbing::Registry<T>>>>,
3535
}
3636

3737
impl<T: IoBufMut> FixedBufRegistry<T> {
@@ -100,7 +100,7 @@ impl<T: IoBufMut> FixedBufRegistry<T> {
100100
/// ```
101101
pub fn new(bufs: impl IntoIterator<Item = T>) -> Self {
102102
FixedBufRegistry {
103-
inner: RefCell::new(Rc::new(RefCell::new(plumbing::Registry::new(
103+
inner: RefCell::new(Arc::new(RefCell::new(plumbing::Registry::new(
104104
bufs.into_iter(),
105105
)))),
106106
}

src/buf/fixed/shared.rs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -3,10 +3,10 @@ use crate::buf::fixed::{FixedBuf, FixedBuffers};
33
use crate::runtime::CONTEXT;
44
use std::cell::RefCell;
55
use std::io;
6-
use std::rc::Rc;
6+
use std::sync::Arc;
77

88
pub(crate) fn process(
9-
this: Rc<RefCell<dyn FixedBuffers>>,
9+
this: Arc<RefCell<dyn FixedBuffers>>,
1010
cob: Option<CheckedOutBuf>,
1111
) -> Option<FixedBuf> {
1212
cob.map(|data| {
@@ -16,7 +16,7 @@ pub(crate) fn process(
1616
})
1717
}
1818

19-
pub(crate) fn register(this: Rc<RefCell<dyn FixedBuffers>>) -> io::Result<()> {
19+
pub(crate) fn register(this: Arc<RefCell<dyn FixedBuffers>>) -> io::Result<()> {
2020
CONTEXT.with(|x| x.handle().register_buffers(this))
2121
}
2222

src/io/shared_fd.rs

Lines changed: 6 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,15 +1,14 @@
11
use std::future::poll_fn;
22

3+
use crate::runtime::driver::op::Op;
4+
use std::sync::Arc;
35
use std::{
46
cell::RefCell,
57
io,
68
os::unix::io::{FromRawFd, RawFd},
7-
rc::Rc,
89
task::Waker,
910
};
1011

11-
use crate::runtime::driver::op::Op;
12-
1312
// Tracks in-flight operations on a file descriptor. Ensures all in-flight
1413
// operations complete before submitting the close.
1514
//
@@ -20,7 +19,7 @@ use crate::runtime::driver::op::Op;
2019
// Only the first close call returns the true result of closing the file descriptor.
2120
#[derive(Clone)]
2221
pub(crate) struct SharedFd {
23-
inner: Rc<Inner>,
22+
inner: Arc<Inner>,
2423
}
2524

2625
unsafe impl Send for SharedFd {}
@@ -49,7 +48,7 @@ enum State {
4948
impl SharedFd {
5049
pub(crate) fn new(fd: RawFd) -> SharedFd {
5150
SharedFd {
52-
inner: Rc::new(Inner {
51+
inner: Arc::new(Inner {
5352
fd,
5453
state: RefCell::new(State::Init),
5554
}),
@@ -69,7 +68,7 @@ impl SharedFd {
6968
loop {
7069
// Get a mutable reference to Inner, indicating there are no
7170
// in-flight operations on the FD.
72-
if let Some(inner) = Rc::get_mut(&mut self.inner) {
71+
if let Some(inner) = Arc::get_mut(&mut self.inner) {
7372
// Wait for the close operation.
7473
return inner.async_close_op().await;
7574
}
@@ -84,7 +83,7 @@ impl SharedFd {
8483
use std::task::Poll;
8584

8685
poll_fn(|cx| {
87-
if Rc::<Inner>::strong_count(&self.inner) == 1 {
86+
if Arc::<Inner>::strong_count(&self.inner) == 1 {
8887
return Poll::Ready(());
8988
}
9089

src/runtime/context.rs

Lines changed: 4 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,8 @@
11
use crate::runtime::driver::{Handle, WeakHandle};
2-
use std::cell::{Cell, OnceCell, RefCell, RefMut};
2+
use std::cell::{OnceCell, RefCell, RefMut};
33
use std::ops::{Deref, DerefMut};
44
use std::os::fd::{AsRawFd, RawFd};
55

6-
fn noop() {}
7-
86
pub(crate) struct RefOnceCell<T> {
97
cell: OnceCell<T>,
108
}
@@ -34,15 +32,13 @@ impl<T> DerefMut for RefOnceCell<T> {
3432
/// Owns the driver and resides in thread-local storage.
3533
pub(crate) struct RuntimeContext {
3634
driver: RefCell<RefOnceCell<Handle>>,
37-
on_thread_park: Cell<fn()>,
3835
}
3936

4037
impl RuntimeContext {
4138
/// Construct the context with an uninitialized driver.
4239
pub(crate) fn new() -> RuntimeContext {
4340
RuntimeContext {
4441
driver: RefCell::new(Default::default()),
45-
on_thread_park: Cell::new(noop),
4642
}
4743
}
4844

@@ -65,13 +61,10 @@ impl RuntimeContext {
6561
let _ = roc.flush();
6662
}
6763

68-
#[inline(always)]
69-
pub(crate) fn call_on_thread_park(&self) {
70-
self.on_thread_park.get()();
71-
}
72-
7364
pub(crate) fn set_on_thread_park(&self, callback: fn()) {
74-
self.on_thread_park.set(callback)
65+
let roc = unsafe { &*self.driver.as_ptr() };
66+
67+
roc.set_on_thread_park(callback)
7568
}
7669

7770
/// Initialize the driver.

src/runtime/driver/handle.rs

Lines changed: 17 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -20,12 +20,12 @@ use std::cell::RefCell;
2020
use std::io;
2121
use std::ops::Deref;
2222
use std::os::unix::io::{AsRawFd, RawFd};
23-
use std::rc::{Rc, Weak};
23+
use std::sync::{Arc, Weak};
2424
use std::task::{Context, Poll};
2525

2626
#[derive(Clone)]
2727
pub(crate) struct Handle {
28-
pub(super) inner: Rc<Driver>,
28+
pub(super) inner: Arc<Driver>,
2929
}
3030

3131
//SAFETY: Handle is only used in RuntimeContext,
@@ -45,7 +45,7 @@ unsafe impl Sync for WeakHandle {}
4545
impl Handle {
4646
pub(crate) fn new(b: &crate::Builder) -> io::Result<Self> {
4747
Ok(Self {
48-
inner: Rc::new(Driver::new(b)?),
48+
inner: Arc::new(Driver::new(b)?),
4949
})
5050
}
5151

@@ -59,19 +59,27 @@ impl Handle {
5959
}
6060

6161
pub(crate) fn flush(&self) -> io::Result<usize> {
62-
self.inner.as_ref().uring.submit()
62+
self.inner.as_ref().flush()
63+
}
64+
65+
pub(crate) fn call_on_thread_park(&self) {
66+
self.inner.as_ref().call_on_thread_park();
67+
}
68+
69+
pub(crate) fn set_on_thread_park(&self, callback: fn()) {
70+
self.inner.as_ref().set_on_thread_park(callback);
6371
}
6472

6573
pub(crate) fn register_buffers(
6674
&mut self,
67-
buffers: Rc<RefCell<dyn FixedBuffers>>,
75+
buffers: Arc<RefCell<dyn FixedBuffers>>,
6876
) -> io::Result<()> {
69-
let inner = Rc::get_mut(&mut self.inner).unwrap();
77+
let inner = Arc::get_mut(&mut self.inner).unwrap();
7078
inner.register_buffers(buffers)
7179
}
7280

7381
pub(crate) fn unregister_buffers(&mut self) -> io::Result<()> {
74-
let inner = Rc::get_mut(&mut self.inner).unwrap();
82+
let inner = Arc::get_mut(&mut self.inner).unwrap();
7583
inner.unregister_buffers()
7684
}
7785

@@ -152,7 +160,7 @@ impl AsRawFd for Handle {
152160
impl From<Driver> for Handle {
153161
fn from(driver: Driver) -> Self {
154162
Self {
155-
inner: Rc::new(driver),
163+
inner: Arc::new(driver),
156164
}
157165
}
158166
}
@@ -163,7 +171,7 @@ where
163171
{
164172
fn from(handle: T) -> Self {
165173
Self {
166-
inner: Rc::downgrade(&handle.inner),
174+
inner: Arc::downgrade(&handle.inner),
167175
}
168176
}
169177
}

0 commit comments

Comments
 (0)