@@ -233,7 +233,7 @@ pub(crate) trait ObjectInterface: Sync + Send + core::fmt::Debug {
233233
234234 /// `accept` a connection on a socket
235235 #[ cfg( any( feature = "net" , feature = "vsock" ) ) ]
236- async fn accept ( & self ) -> io:: Result < ( Arc < dyn ObjectInterface > , Endpoint ) > {
236+ async fn accept ( & self ) -> io:: Result < ( Arc < async_lock :: RwLock < dyn ObjectInterface > > , Endpoint ) > {
237237 Err ( Errno :: Inval )
238238 }
239239
@@ -337,19 +337,19 @@ pub(crate) fn read(fd: FileDescriptor, buf: &mut [u8]) -> io::Result<usize> {
337337 return Ok ( 0 ) ;
338338 }
339339
340- block_on ( obj. read ( buf) , None )
340+ block_on ( async { obj. read ( ) . await . read ( buf) . await } , None )
341341}
342342
343343pub ( crate ) fn lseek ( fd : FileDescriptor , offset : isize , whence : SeekWhence ) -> io:: Result < isize > {
344344 let obj = get_object ( fd) ?;
345345
346- block_on ( obj. lseek ( offset, whence) , None )
346+ block_on ( async { obj. read ( ) . await . lseek ( offset, whence) . await } , None )
347347}
348348
349349pub ( crate ) fn chmod ( fd : FileDescriptor , mode : AccessPermission ) -> io:: Result < ( ) > {
350350 let obj = get_object ( fd) ?;
351351
352- block_on ( obj. chmod ( mode) , None )
352+ block_on ( async { obj. read ( ) . await . chmod ( mode) . await } , None )
353353}
354354
355355pub ( crate ) fn write ( fd : FileDescriptor , buf : & [ u8 ] ) -> io:: Result < usize > {
@@ -359,12 +359,12 @@ pub(crate) fn write(fd: FileDescriptor, buf: &[u8]) -> io::Result<usize> {
359359 return Ok ( 0 ) ;
360360 }
361361
362- block_on ( obj. write ( buf) , None )
362+ block_on ( async { obj. read ( ) . await . write ( buf) . await } , None )
363363}
364364
365365pub ( crate ) fn truncate ( fd : FileDescriptor , length : usize ) -> io:: Result < ( ) > {
366366 let obj = get_object ( fd) ?;
367- block_on ( obj. truncate ( length) , None )
367+ block_on ( async { obj. read ( ) . await . truncate ( length) . await } , None )
368368}
369369
370370async fn poll_fds ( fds : & mut [ PollFd ] ) -> io:: Result < u64 > {
@@ -375,7 +375,7 @@ async fn poll_fds(fds: &mut [PollFd]) -> io::Result<u64> {
375375 let fd = i. fd ;
376376 i. revents = PollEvent :: empty ( ) ;
377377 if let Ok ( obj) = core_scheduler ( ) . get_object ( fd) {
378- let mut pinned = core:: pin:: pin!( obj. poll( i. events) ) ;
378+ let mut pinned = core:: pin:: pin!( async { obj. read ( ) . await . poll( i. events) . await } ) ;
379379 if let Ready ( Ok ( e) ) = pinned. as_mut ( ) . poll ( cx)
380380 && !e. is_empty ( )
381381 {
@@ -416,7 +416,7 @@ pub fn poll(fds: &mut [PollFd], timeout: Option<Duration>) -> io::Result<u64> {
416416
417417pub fn fstat ( fd : FileDescriptor ) -> io:: Result < FileAttr > {
418418 let obj = get_object ( fd) ?;
419- block_on ( obj. fstat ( ) , None )
419+ block_on ( async { obj. read ( ) . await . fstat ( ) . await } , None )
420420}
421421
422422/// Wait for some event on a file descriptor.
@@ -440,16 +440,20 @@ pub fn fstat(fd: FileDescriptor) -> io::Result<FileAttr> {
440440pub fn eventfd ( initval : u64 , flags : EventFlags ) -> io:: Result < FileDescriptor > {
441441 let obj = self :: eventfd:: EventFd :: new ( initval, flags) ;
442442
443- let fd = core_scheduler ( ) . insert_object ( Arc :: new ( obj) ) ?;
443+ let fd = core_scheduler ( ) . insert_object ( Arc :: new ( async_lock :: RwLock :: new ( obj) ) ) ?;
444444
445445 Ok ( fd)
446446}
447447
448- pub ( crate ) fn get_object ( fd : FileDescriptor ) -> io:: Result < Arc < dyn ObjectInterface > > {
448+ pub ( crate ) fn get_object (
449+ fd : FileDescriptor ,
450+ ) -> io:: Result < Arc < async_lock:: RwLock < dyn ObjectInterface > > > {
449451 core_scheduler ( ) . get_object ( fd)
450452}
451453
452- pub ( crate ) fn insert_object ( obj : Arc < dyn ObjectInterface > ) -> io:: Result < FileDescriptor > {
454+ pub ( crate ) fn insert_object (
455+ obj : Arc < async_lock:: RwLock < dyn ObjectInterface > > ,
456+ ) -> io:: Result < FileDescriptor > {
453457 core_scheduler ( ) . insert_object ( obj)
454458}
455459
@@ -465,11 +469,13 @@ pub(crate) fn dup_object2(fd1: FileDescriptor, fd2: FileDescriptor) -> io::Resul
465469 core_scheduler ( ) . dup_object2 ( fd1, fd2)
466470}
467471
468- pub ( crate ) fn remove_object ( fd : FileDescriptor ) -> io:: Result < Arc < dyn ObjectInterface > > {
472+ pub ( crate ) fn remove_object (
473+ fd : FileDescriptor ,
474+ ) -> io:: Result < Arc < async_lock:: RwLock < dyn ObjectInterface > > > {
469475 core_scheduler ( ) . remove_object ( fd)
470476}
471477
472478pub ( crate ) fn isatty ( fd : FileDescriptor ) -> io:: Result < bool > {
473479 let obj = get_object ( fd) ?;
474- block_on ( obj. isatty ( ) , None )
480+ block_on ( async { obj. read ( ) . await . isatty ( ) . await } , None )
475481}
0 commit comments