@@ -6,7 +6,6 @@ use std::ffi::c_int;
66use std:: ops:: Range ;
77use std:: ptr;
88use std:: sync:: Arc ;
9- use std:: sync:: Mutex ;
109
1110use arrow_array:: RecordBatch ;
1211use arrow_array:: cast:: AsArray ;
@@ -43,12 +42,11 @@ use crate::error::vx_error;
4342use crate :: expression:: vx_expression;
4443use crate :: session:: vx_session;
4544
46- pub enum VxScanState {
45+ pub enum VxScan {
4746 Pending ( Box < dyn DataSourceScan > ) ,
4847 Started ( PartitionStream ) ,
4948 Finished ,
5049}
51- pub type VxScan = Mutex < VxScanState > ;
5250crate :: box_wrapper!( VxScan , vx_scan) ;
5351
5452pub enum VxPartitionScan {
@@ -233,7 +231,7 @@ pub unsafe extern "C-unwind" fn vx_data_source_scan(
233231 unsafe { & mut * estimate } ,
234232 ) ;
235233 }
236- Ok ( vx_scan:: new ( Mutex :: new ( VxScanState :: Pending ( scan) ) ) )
234+ Ok ( vx_scan:: new ( VxScan :: Pending ( scan) ) )
237235 } )
238236 } )
239237}
@@ -249,8 +247,8 @@ pub unsafe extern "C-unwind" fn vx_scan_dtype(
249247 err : * mut * mut vx_error ,
250248) -> * const vx_dtype {
251249 try_or ( err, ptr:: null ( ) , || {
252- let scan = vx_scan:: as_ref ( scan) . lock ( ) . expect ( "failed to lock mutex" ) ;
253- let VxScanState :: Pending ( ref scan) = * scan else {
250+ let scan = vx_scan:: as_ref ( scan) ;
251+ let VxScan :: Pending ( ref scan) = * scan else {
254252 vortex_bail ! ( "dtype unavailable: scan already started" ) ;
255253 } ;
256254 Ok ( vx_dtype:: new_ref ( scan. dtype ( ) ) )
@@ -265,22 +263,21 @@ pub unsafe extern "C-unwind" fn vx_scan_dtype(
265263/// "err".
266264/// On error returns NULL and sets "err".
267265///
268- /// This function is thread-safe: callers running a multi-threaded pipeline
269- /// should call it concurrently and dispatch each partition to a dedicated
270- /// worker thread.
266+ /// This function is thread-unsafe. Callers running a multi-threaded pipeline
267+ /// should synchronise on calls to this function and dispatch each produced
268+ /// partition to a dedicated worker thread.
271269#[ unsafe( no_mangle) ]
272270pub unsafe extern "C-unwind" fn vx_scan_next_partition (
273271 scan : * mut vx_scan ,
274272 err : * mut * mut vx_error ,
275273) -> * mut vx_partition {
276274 let scan = vx_scan:: as_mut ( scan) ;
277- let mut scan = scan. lock ( ) . expect ( "failed to lock mutex" ) ;
278275 let scan = & mut * scan;
279276 unsafe {
280- let ptr = scan as * mut VxScanState ;
277+ let ptr = scan as * mut VxScan ;
281278
282279 let on_finish = || -> VortexResult < * mut vx_partition > {
283- ptr:: write ( ptr, VxScanState :: Finished ) ;
280+ ptr:: write ( ptr, VxScan :: Finished ) ;
284281 Ok ( ptr:: null_mut ( ) )
285282 } ;
286283
@@ -289,7 +286,7 @@ pub unsafe extern "C-unwind" fn vx_scan_next_partition(
289286 Some ( partition) => {
290287 let partition = VxPartitionScan :: Pending ( partition?) ;
291288 let partition = vx_partition:: new ( partition) ;
292- ptr:: write ( ptr, VxScanState :: Started ( stream) ) ;
289+ ptr:: write ( ptr, VxScan :: Started ( stream) ) ;
293290 Ok ( partition)
294291 }
295292 None => on_finish ( ) ,
@@ -298,9 +295,9 @@ pub unsafe extern "C-unwind" fn vx_scan_next_partition(
298295
299296 let owned = ptr:: read ( ptr) ;
300297 try_or_default ( err, || match owned {
301- VxScanState :: Pending ( scan) => on_stream ( scan. partitions ( ) ) ,
302- VxScanState :: Started ( stream) => on_stream ( stream) ,
303- VxScanState :: Finished => on_finish ( ) ,
298+ VxScan :: Pending ( scan) => on_stream ( scan. partitions ( ) ) ,
299+ VxScan :: Started ( stream) => on_stream ( stream) ,
300+ VxScan :: Finished => on_finish ( ) ,
304301 } )
305302 }
306303}
0 commit comments