@@ -21,7 +21,7 @@ use rand::RngExt;
2121use siphasher:: sip128:: { Hasher128 , SipHasher24 } ;
2222use wasmtime:: component:: { HasData , Resource } ;
2323use wasmtime_wasi:: {
24- ResourceTable ,
24+ ResourceTable , async_trait ,
2525 filesystem:: Descriptor ,
2626 p2:: {
2727 FsError , FsResult , InputStream as WasiInputStream , OutputStream as WasiOutputStream ,
@@ -406,34 +406,25 @@ struct VfsOutputStream {
406406 /// The file node to write to.
407407 node : SharedVfsNode ,
408408 /// Current write offset in the file.
409- offset : Arc < AtomicU64 > ,
409+ offset : u64 ,
410410 /// Resource limiter for memory accounting.
411411 limiter : Limiter ,
412412}
413413
414414impl std:: fmt:: Debug for VfsOutputStream {
415415 fn fmt ( & self , f : & mut std:: fmt:: Formatter < ' _ > ) -> std:: fmt:: Result {
416416 f. debug_struct ( "VfsOutputStream" )
417- . field ( "offset" , & self . offset . load ( Ordering :: SeqCst ) )
417+ . field ( "offset" , & self . offset )
418418 . finish_non_exhaustive ( )
419419 }
420420}
421421
422+ #[ async_trait]
422423impl Pollable for VfsOutputStream {
423- fn ready < ' life0 , ' async_trait > (
424- & ' life0 mut self ,
425- ) -> :: core:: pin:: Pin <
426- Box < dyn :: core:: future:: Future < Output = ( ) > + :: core:: marker:: Send + ' async_trait > ,
427- >
428- where
429- ' life0 : ' async_trait ,
430- Self : ' async_trait ,
431- {
432- Box :: pin ( async move {
433- // Wait until the stream is ready for writing. For an in-memory
434- // stream, this is always the case, so we can just return
435- // immediately.
436- } )
424+ async fn ready ( & mut self ) {
425+ // Wait until the stream is ready for writing. For an in-memory
426+ // stream, this is always the case, so we can just return
427+ // immediately.
437428 }
438429}
439430
@@ -443,14 +434,9 @@ impl WasiOutputStream for VfsOutputStream {
443434 return Ok ( ( ) ) ;
444435 }
445436
446- match perform_write (
447- & self . node ,
448- self . offset . load ( Ordering :: SeqCst ) as usize ,
449- & buf,
450- & self . limiter ,
451- ) {
437+ match perform_write ( & self . node , self . offset as usize , & buf, & self . limiter ) {
452438 Ok ( nbyte) => {
453- self . offset . fetch_add ( nbyte , Ordering :: SeqCst ) ;
439+ self . offset += nbyte ;
454440 Ok ( ( ) )
455441 }
456442 Err ( e) => Err ( StreamError :: Trap ( e. into ( ) ) ) ,
@@ -609,7 +595,7 @@ impl<'a> filesystem::types::HostDescriptor for VfsCtxView<'a> {
609595 VfsNodeKind :: File { .. } => {
610596 let stream = VfsOutputStream {
611597 node : Arc :: clone ( & node) ,
612- offset : Arc :: new ( AtomicU64 :: new ( offset ) ) ,
598+ offset,
613599 limiter,
614600 } ;
615601 let stream: Box < dyn WasiOutputStream > = Box :: new ( stream) ;
0 commit comments