Skip to content

Commit eb8d3a9

Browse files
author
Lucas Paixão
committed
Code indentation and reshaping
1 parent 53f14b2 commit eb8d3a9

File tree

3 files changed

+123
-94
lines changed

3 files changed

+123
-94
lines changed

src/runtime/driver/handle.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -125,7 +125,7 @@ impl Handle {
125125
where
126126
T: Unpin + 'static + Completable,
127127
{
128-
self.inner.as_ref().poll_op_oneshot(op, cx)
128+
self.inner.as_ref().poll_oneshot_op(op, cx)
129129
}
130130

131131
pub(crate) fn poll_multishot_op<T>(

src/runtime/driver/mod.rs

Lines changed: 22 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
use crate::buf::fixed::FixedBuffers;
22
use crate::runtime::driver::op::{
3-
ArcMonitor, Completable, CqeResult, Lifecycle, Location, MultiCQE, Notifiable, OneshotCQE, Op,
3+
ArcMonitor, Completable, CqeResult, Lifecycle, MultiCQE, OneshotCQE, Op,
44
Updateable,
55
};
66
pub(crate) use handle::*;
@@ -12,7 +12,7 @@ use std::pin::Pin;
1212
use std::rc::Rc;
1313
use std::sync::atomic::{AtomicBool, AtomicUsize, Ordering};
1414
use std::task::{Context, Poll};
15-
use std::{io, mem};
15+
use std::{io, mem, ptr};
1616

1717
mod handle;
1818
pub(crate) mod op;
@@ -144,9 +144,7 @@ impl Driver {
144144

145145
// SAFETY: The user_data field of the CQE is a pointer to Location struct
146146
// which Future is pinned in memory.
147-
let location: &mut ArcMonitor<Location> = unsafe { mem::transmute(cqe.user_data()) };
148-
let notifiable: &mut dyn Notifiable =
149-
unsafe { mem::transmute((location.address, location.vtable)) };
147+
let arc_monitor: &mut ArcMonitor<Lifecycle> = unsafe { mem::transmute(cqe.user_data()) };
150148

151149
let mut is_last = false;
152150

@@ -159,14 +157,13 @@ impl Driver {
159157
// Only notify if the result is not ECANCELED
160158
// and Op is not dropped.
161159
if cqe.result() != -libc::ECANCELED {
162-
// This will delay the drop of the Op until leave call
163-
if let Some(_guard) = location.try_enter() {
164-
notifiable.notify(cqe);
165-
}
160+
arc_monitor.try_execute(|lifecycle|{
161+
lifecycle.complete(cqe);
162+
});
166163
}
167164

168165
if is_last {
169-
location.quit();
166+
arc_monitor.quit();
170167
self.pending_number.fetch_sub(1, Ordering::Release);
171168
}
172169
}
@@ -207,7 +204,9 @@ impl Driver {
207204
// Get the Op Lifecycle state from the driver
208205
let lifecycle = op.get_lifecycle();
209206

210-
match mem::replace(lifecycle, Lifecycle::Submitted) {
207+
let current = mem::replace(lifecycle, Lifecycle::Submitted);
208+
209+
match current {
211210
Lifecycle::Submitted | Lifecycle::Waiting(_) => {
212211
Driver::set_ignored(op);
213212
}
@@ -224,7 +223,7 @@ impl Driver {
224223
_ => {}
225224
}
226225

227-
let location: &mut ArcMonitor<Location> = unsafe { mem::transmute(op.location()) };
226+
let location: &mut ArcMonitor<Lifecycle> = unsafe { mem::transmute(op.location()) };
228227

229228
location.try_recycle(true);
230229
}
@@ -273,7 +272,7 @@ impl Driver {
273272
Ok(op)
274273
}
275274

276-
pub(crate) fn poll_op_oneshot<T>(
275+
pub(crate) fn poll_oneshot_op<T>(
277276
&self,
278277
op: &mut Op<T, OneshotCQE>,
279278
cx: &mut Context<'_>,
@@ -283,7 +282,9 @@ impl Driver {
283282
{
284283
let lifecycle = op.get_lifecycle();
285284

286-
match mem::replace(lifecycle, Lifecycle::Submitted) {
285+
let current = mem::replace(lifecycle, Lifecycle::Submitted);
286+
287+
match current {
287288
Lifecycle::Initial | Lifecycle::Submitted => {
288289
*lifecycle = Lifecycle::Waiting(cx.waker().clone());
289290
Poll::Pending
@@ -310,7 +311,9 @@ impl Driver {
310311
{
311312
let lifecycle = op.get_lifecycle();
312313

313-
match mem::replace(lifecycle, Lifecycle::Submitted) {
314+
let current = mem::replace(lifecycle, Lifecycle::Submitted);
315+
316+
match current {
314317
Lifecycle::Submitted | Lifecycle::Initial => {
315318
*lifecycle = Lifecycle::Waiting(cx.waker().clone());
316319
Poll::Pending
@@ -373,7 +376,9 @@ impl Driver {
373376
{
374377
let lifecycle = op.get_lifecycle();
375378

376-
match mem::replace(lifecycle, Lifecycle::Submitted) {
379+
let current = mem::replace(lifecycle, Lifecycle::Submitted);
380+
381+
match current {
377382
Lifecycle::Initial | Lifecycle::Submitted => {
378383
*lifecycle = Lifecycle::Waiting(cx.waker().clone());
379384
Poll::Pending
@@ -522,4 +527,4 @@ mod test {
522527
assert_eq!(num_operations(), 0);
523528
});
524529
}
525-
}
530+
}

0 commit comments

Comments
 (0)