@@ -18,7 +18,6 @@ use std::sync::Arc;
18
18
use std:: sync:: Mutex ;
19
19
use std:: sync:: Once ;
20
20
use std:: time:: Duration ;
21
- use std:: time:: SystemTime ;
22
21
23
22
use amalthea:: events:: BusyEvent ;
24
23
use amalthea:: events:: PositronEvent ;
@@ -49,8 +48,6 @@ use harp::exec::r_source;
49
48
use harp:: exec:: RFunction ;
50
49
use harp:: exec:: RFunctionExt ;
51
50
use harp:: interrupts:: RInterruptsSuspendedScope ;
52
- use harp:: lock:: R_RUNTIME_LOCK ;
53
- use harp:: lock:: R_RUNTIME_LOCK_COUNT ;
54
51
use harp:: object:: RObject ;
55
52
use harp:: r_safely;
56
53
use harp:: r_symbol;
@@ -61,7 +58,6 @@ use harp::utils::r_is_data_frame;
61
58
use libR_sys:: * ;
62
59
use log:: * ;
63
60
use nix:: sys:: signal:: * ;
64
- use parking_lot:: ReentrantMutexGuard ;
65
61
use serde_json:: json;
66
62
use stdext:: result:: ResultOrLog ;
67
63
use stdext:: * ;
@@ -267,12 +263,10 @@ pub struct RMain {
267
263
stderr : String ,
268
264
banner : String ,
269
265
270
- /// A lock guard, used to manage access to the R runtime. The main
271
- /// thread holds the lock by default, but releases it at opportune
272
- /// times to allow the LSP to access the R runtime where appropriate.
273
- runtime_lock_guard : Option < ReentrantMutexGuard < ' static , ( ) > > ,
266
+ /// The ID of the R thread
274
267
pub thread_id : std:: thread:: ThreadId ,
275
268
269
+ /// Channel to receive tasks from `r_task()`
276
270
pub tasks_tx : Sender < RTaskMain > ,
277
271
tasks_rx : Receiver < RTaskMain > ,
278
272
@@ -355,10 +349,6 @@ impl RMain {
355
349
kernel_init_tx : Bus < KernelInfo > ,
356
350
dap : Arc < Mutex < Dap > > ,
357
351
) -> Self {
358
- // The main thread owns the R runtime lock by default, but releases
359
- // it when appropriate to give other threads a chance to execute.
360
- let lock_guard = unsafe { R_RUNTIME_LOCK . lock ( ) } ;
361
-
362
352
// Channel to receive tasks from auxiliary threads via `r_task()`
363
353
let ( tasks_tx, tasks_rx) = unbounded :: < RTaskMain > ( ) ;
364
354
@@ -373,7 +363,6 @@ impl RMain {
373
363
stdout : String :: new ( ) ,
374
364
stderr : String :: new ( ) ,
375
365
banner : String :: new ( ) ,
376
- runtime_lock_guard : Some ( lock_guard) ,
377
366
kernel,
378
367
error_occurred : false ,
379
368
error_message : String :: new ( ) ,
@@ -597,8 +586,7 @@ impl RMain {
597
586
// descriptors that R has open and select() on those for
598
587
// available data?
599
588
loop {
600
- // Release the R runtime lock while we're waiting for input.
601
- self . runtime_lock_guard = None ;
589
+ // Yield to auxiliary threads.
602
590
self . run_one_task ( ) ;
603
591
604
592
// FIXME: Race between interrupt and new code request. To fix
@@ -640,9 +628,6 @@ impl RMain {
640
628
} ,
641
629
} ;
642
630
643
- // Take back the lock after we've received some console input.
644
- unsafe { self . runtime_lock_guard = Some ( R_RUNTIME_LOCK . lock ( ) ) } ;
645
-
646
631
if Self :: process_interrupts ( & info) {
647
632
return ( 0 , true ) ;
648
633
}
@@ -670,8 +655,6 @@ impl RMain {
670
655
}
671
656
} ,
672
657
Err ( err) => {
673
- unsafe { self . runtime_lock_guard = Some ( R_RUNTIME_LOCK . lock ( ) ) } ;
674
-
675
658
use RecvTimeoutError :: * ;
676
659
match err {
677
660
Timeout => {
@@ -879,27 +862,6 @@ impl RMain {
879
862
fn polled_events ( & mut self ) {
880
863
// Check for pending tasks.
881
864
self . run_one_task ( ) ;
882
-
883
- let count = R_RUNTIME_LOCK_COUNT . load ( std:: sync:: atomic:: Ordering :: Acquire ) ;
884
- if count == 0 {
885
- return ;
886
- }
887
-
888
- info ! (
889
- "{} thread(s) are waiting; the main thread is releasing the R runtime lock." ,
890
- count
891
- ) ;
892
- let now = SystemTime :: now ( ) ;
893
-
894
- // `bump()` does a fair unlock, giving other threads
895
- // waiting for the lock a chance to acquire it, and then
896
- // relocks it.
897
- ReentrantMutexGuard :: bump ( self . runtime_lock_guard . as_mut ( ) . unwrap ( ) ) ;
898
-
899
- info ! (
900
- "The main thread re-acquired the R runtime lock after {} milliseconds." ,
901
- now. elapsed( ) . unwrap( ) . as_millis( )
902
- ) ;
903
865
}
904
866
905
867
unsafe fn process_events ( ) {
0 commit comments