@@ -44,8 +44,6 @@ pub struct SharedState {
4444 pub analog_values : [ u8 ; 0xFF ] ,
4545}
4646
47- unsafe impl SharedMemCast for SharedState { }
48-
4947impl WootingAnalogTestPlugin {
5048 fn new ( ) -> Self {
5149 if let Err ( e) = env_logger:: try_init ( ) {
@@ -68,8 +66,8 @@ impl WootingAnalogTestPlugin {
6866
6967 let worker_thread = thread:: spawn ( move || {
7068 let link_path = std:: env:: temp_dir ( ) . join ( "wooting-test-plugin.link" ) ;
71- let mut my_shmem = {
72- match SharedMem :: open_linked ( link_path. as_os_str ( ) ) {
69+ let my_shmem = {
70+ match ShmemConf :: new ( ) . size ( 4096 ) . flink ( link_path. as_os_str ( ) ) . open ( ) {
7371 Ok ( v) => v,
7472 Err ( e) => {
7573 if link_path. exists ( ) {
@@ -79,7 +77,7 @@ impl WootingAnalogTestPlugin {
7977 error ! ( "Could not delete old link file: {}" , e) ;
8078 }
8179 }
82- match SharedMem :: create_linked ( link_path. as_os_str ( ) , LockType :: Mutex , 4096 )
80+ match ShmemConf :: new ( ) . size ( 4096 ) . flink ( link_path. as_os_str ( ) ) . create ( )
8381 {
8482 Ok ( m) => m,
8583 Err ( e) => {
@@ -93,16 +91,10 @@ impl WootingAnalogTestPlugin {
9391 }
9492 } ;
9593
96- info ! ( "{:?}" , my_shmem. get_link_path ( ) ) ;
94+ info ! ( "{:?}" , my_shmem. get_flink_path ( ) ) ;
9795
9896 {
99- let mut shared_state = match my_shmem. wlock :: < SharedState > ( 0 ) {
100- Ok ( v) => v,
101- Err ( _) => {
102- error ! ( "Test plugin Failed to acquire write lock! Stopping..." ) ;
103- return ;
104- }
105- } ;
97+ let shared_state = unsafe { & mut * ( my_shmem. as_ptr ( ) as * mut u8 as * mut SharedState ) } ;
10698 shared_state. vendor_id = 0x03eb ;
10799 shared_state. product_id = 0xFFFF ;
108100 shared_state. device_type = DeviceType :: Keyboard ;
@@ -122,13 +114,7 @@ impl WootingAnalogTestPlugin {
122114 }
123115
124116 {
125- let mut state = match my_shmem. wlock :: < SharedState > ( 0 ) {
126- Ok ( v) => v,
127- Err ( _) => {
128- warn ! ( "failed to get lock" ) ;
129- continue ;
130- }
131- } ;
117+ let state = unsafe { & mut * ( my_shmem. as_ptr ( ) as * mut u8 as * mut SharedState ) } ;
132118
133119 if state. dirty_device_info || t_device. lock ( ) . unwrap ( ) . is_none ( ) {
134120 state. dirty_device_info = false ;
@@ -166,8 +152,6 @@ impl WootingAnalogTestPlugin {
166152 }
167153
168154 if !state. device_connected {
169- //make sure we drop the state so we're not holding the lock while the thread is sleeping
170- drop ( state) ;
171155 thread:: sleep ( Duration :: from_millis ( 500 ) ) ;
172156 continue ;
173157 }
0 commit comments