File tree Expand file tree Collapse file tree 4 files changed +55
-4
lines changed Expand file tree Collapse file tree 4 files changed +55
-4
lines changed Original file line number Diff line number Diff line change @@ -34,10 +34,32 @@ pub(crate) struct WeakHandle {
34
34
inner : Weak < RefCell < Driver > > ,
35
35
}
36
36
37
+ struct ThreadParker ;
38
+ impl std:: future:: Future for ThreadParker {
39
+ type Output = ( ) ;
40
+ fn poll (
41
+ self : std:: pin:: Pin < & mut Self > ,
42
+ ctx : & mut std:: task:: Context < ' _ > ,
43
+ ) -> std:: task:: Poll < <Self as std:: future:: Future >:: Output > {
44
+ ctx. waker ( ) . clone ( ) . wake ( ) ;
45
+ std:: task:: Poll :: Pending
46
+ }
47
+ }
48
+
37
49
impl Handle {
38
- pub ( crate ) fn new ( b : & crate :: Builder ) -> io:: Result < Self > {
50
+ pub ( crate ) fn new (
51
+ b : & crate :: Builder ,
52
+ tokio_rt : & tokio:: runtime:: Runtime ,
53
+ local : & tokio:: task:: LocalSet ,
54
+ ) -> io:: Result < Self > {
55
+ let driver = Driver :: new ( b) ?;
56
+ let params = driver. uring . params ( ) ;
57
+ if params. is_setup_iopoll ( ) && !params. is_setup_sqpoll ( ) {
58
+ let _guard = tokio_rt. enter ( ) ;
59
+ local. spawn_local ( ThreadParker { } ) ;
60
+ }
39
61
Ok ( Self {
40
- inner : Rc :: new ( RefCell :: new ( Driver :: new ( b ) ? ) ) ,
62
+ inner : Rc :: new ( RefCell :: new ( driver ) ) ,
41
63
} )
42
64
}
43
65
Original file line number Diff line number Diff line change @@ -19,7 +19,7 @@ pub(crate) struct Driver {
19
19
ops : Ops ,
20
20
21
21
/// IoUring bindings
22
- uring : IoUring ,
22
+ pub ( crate ) uring : IoUring ,
23
23
24
24
/// Reference to the currently registered buffers.
25
25
/// Ensures that the buffers are not dropped until
@@ -40,6 +40,8 @@ impl Driver {
40
40
pub ( crate ) fn new ( b : & crate :: Builder ) -> io:: Result < Driver > {
41
41
let uring = b. urb . build ( b. entries ) ?;
42
42
43
+ if uring. params ( ) . is_setup_iopoll ( ) && !uring. params ( ) . is_setup_sqpoll ( ) { }
44
+
43
45
Ok ( Driver {
44
46
ops : Ops :: new ( ) ,
45
47
uring,
Original file line number Diff line number Diff line change @@ -81,7 +81,7 @@ impl Runtime {
81
81
82
82
let tokio_rt = ManuallyDrop :: new ( rt) ;
83
83
let local = ManuallyDrop :: new ( LocalSet :: new ( ) ) ;
84
- let driver = driver:: Handle :: new ( b) ?;
84
+ let driver = driver:: Handle :: new ( b, & tokio_rt , & local ) ?;
85
85
86
86
start_uring_wakes_task ( & tokio_rt, & local, driver. clone ( ) ) ;
87
87
Original file line number Diff line number Diff line change @@ -315,6 +315,33 @@ fn basic_fallocate() {
315
315
} ) ;
316
316
}
317
317
318
+ #[ test]
319
+ fn iopoll_without_sqpoll ( ) {
320
+ use std:: os:: unix:: fs:: OpenOptionsExt ;
321
+ let mut builder = tokio_uring:: builder ( ) ;
322
+ builder. uring_builder ( & tokio_uring:: uring_builder ( ) . setup_iopoll ( ) ) ;
323
+ let runtime = tokio_uring:: Runtime :: new ( & builder) . unwrap ( ) ;
324
+ let tmp = tempfile ( ) ;
325
+ runtime. block_on ( async {
326
+ let file = std:: fs:: OpenOptions :: new ( )
327
+ . write ( true )
328
+ . custom_flags ( libc:: O_DIRECT )
329
+ . open ( tmp. path ( ) )
330
+ . unwrap ( ) ;
331
+ let file = tokio_uring:: fs:: File :: from_std ( file) ;
332
+
333
+ let layout = std:: alloc:: Layout :: from_size_align ( 512 , 512 ) . unwrap ( ) ;
334
+ let buf = unsafe {
335
+ let raw = std:: alloc:: alloc ( layout) ;
336
+ std:: ptr:: copy ( "asdf" . as_ptr ( ) , raw, 4 ) ;
337
+ std:: slice:: from_raw_parts ( raw, 512 )
338
+ } ;
339
+
340
+ let res = file. write_at ( buf, 0 ) . submit ( ) . await . 0 . unwrap ( ) ;
341
+ assert_eq ! ( res, 512 ) ;
342
+ } ) ;
343
+ }
344
+
318
345
fn tempfile ( ) -> NamedTempFile {
319
346
NamedTempFile :: new ( ) . unwrap ( )
320
347
}
You can’t perform that action at this time.
0 commit comments