@@ -353,9 +353,7 @@ pub extern "C" fn wooting_analog_read_full_buffer_device(
353353mod tests {
354354 use super :: * ;
355355 use crate :: keycode:: hid_to_code;
356- use shared_memory:: {
357- ReadLockGuard , ReadLockable , SharedMem , SharedMemCast , WriteLockGuard , WriteLockable ,
358- } ;
356+ use shared_memory:: ShmemConf ;
359357
360358 use std:: sync:: { Arc , MutexGuard } ;
361359 use std:: time:: Duration ;
@@ -379,8 +377,6 @@ mod tests {
379377 pub analog_values : [ u8 ; 0xFF ] ,
380378 }
381379
382- unsafe impl SharedMemCast for SharedState { }
383-
384380 pub fn get_sdk ( ) -> MutexGuard < ' static , AnalogSDK > {
385381 ANALOG_SDK . lock ( ) . unwrap ( )
386382 }
@@ -409,20 +405,6 @@ mod tests {
409405 info ! ( "Got {:?} after {} attempts" , connected, n) ;
410406 }
411407
412- fn get_wlock ( shmem : & mut SharedMem ) -> WriteLockGuard < SharedState > {
413- match shmem. wlock :: < SharedState > ( 0 ) {
414- Ok ( v) => v,
415- Err ( _) => panic ! ( "Failed to acquire write lock !" ) ,
416- }
417- }
418-
419- fn get_rlock ( shmem : & mut SharedMem ) -> ReadLockGuard < SharedState > {
420- match shmem. rlock :: < SharedState > ( 0 ) {
421- Ok ( v) => v,
422- Err ( _) => panic ! ( "Failed to acquire write lock !" ) ,
423- }
424- }
425-
426408 fn shared_init ( ) {
427409 env_logger:: try_init_from_env ( env_logger:: Env :: from ( "trace" ) )
428410 . map_err ( |e| println ! ( "ERROR: Could not initialise env_logger. '{:?}'" , e) ) ;
@@ -455,11 +437,11 @@ mod tests {
455437 //Wait a slight bit to ensure that the test-plugin worker thread has initialised the shared mem
456438 :: std:: thread:: sleep ( Duration :: from_millis ( 500 ) ) ;
457439
458- let mut shmem = match SharedMem :: open_linked (
440+ let mut shmem = match ShmemConf :: new ( ) . size ( 4096 ) . flink (
459441 std:: env:: temp_dir ( )
460442 . join ( "wooting-test-plugin.link" )
461443 . as_os_str ( ) ,
462- ) {
444+ ) . open ( ) {
463445 Ok ( v) => v,
464446 Err ( e) => {
465447 println ! ( "Error : {}" , e) ;
@@ -474,7 +456,7 @@ mod tests {
474456 //Check the connected cb is called
475457 {
476458 {
477- let mut shared_state = get_wlock ( & mut shmem) ;
459+ let shared_state = unsafe { & mut * ( shmem. as_ptr ( ) as * mut u8 as * mut SharedState ) } ;
478460 shared_state. device_connected = true ;
479461 }
480462 wait_for_connected ( 5 , true ) ;
@@ -506,7 +488,7 @@ mod tests {
506488 //Check the cb is called with disconnected
507489 {
508490 {
509- let mut shared_state = get_wlock ( & mut shmem) ;
491+ let shared_state = unsafe { & mut * ( shmem. as_ptr ( ) as * mut u8 as * mut SharedState ) } ;
510492 shared_state. device_connected = false ;
511493 }
512494 wait_for_connected ( 5 , false ) ;
@@ -529,7 +511,7 @@ mod tests {
529511 let analog_key = 5 ;
530512 //Connect the device again, set a keycode to a val
531513 let device_id = {
532- let mut shared_state = get_wlock ( & mut shmem) ;
514+ let shared_state = unsafe { & mut * ( shmem. as_ptr ( ) as * mut u8 as * mut SharedState ) } ;
533515 shared_state. analog_values [ analog_key] = analog_val;
534516 shared_state. device_connected = true ;
535517 1
@@ -632,7 +614,7 @@ mod tests {
632614 wooting_analog_set_keycode_mode ( mode. clone ( ) as u32 ) ;
633615
634616 {
635- let mut shared_state = get_wlock ( & mut shmem) ;
617+ let shared_state = unsafe { & mut * ( shmem. as_ptr ( ) as * mut u8 as * mut SharedState ) } ;
636618 shared_state. analog_values [ analog_key] = 0 ;
637619 }
638620 :: std:: thread:: sleep ( Duration :: from_secs ( 1 ) ) ;
@@ -668,7 +650,7 @@ mod tests {
668650 WootingAnalogResult :: Ok
669651 ) ;
670652 {
671- let mut shared_state = get_wlock ( & mut shmem) ;
653+ let shared_state = unsafe { & mut * ( shmem. as_ptr ( ) as * mut u8 as * mut SharedState ) } ;
672654 shared_state. device_connected = false ;
673655 }
674656 :: std:: thread:: sleep ( Duration :: from_secs ( 1 ) ) ;
0 commit comments