Skip to content

Commit 897c495

Browse files
committed
Fix sharing of ThreadStatus
Application was creating two instances of Runtime, the first instance was only being used to create a ThreadStatus that was passed to Process. The second instance was the real Runtime, that would handle all the thread management and status tracking. The problem, was that Process had an incorrect copy of ThreadStatus, so the status checks Process performed were not completing. This resulted in things like the External Editor functionality stalling, when it was waiting for thread status updated. This change creates a single instance of the ThreadStatus that is shared across the Process and Runtime.
1 parent 1ec3d3e commit 897c495

File tree

4 files changed

+18
-17
lines changed

4 files changed

+18
-17
lines changed

src/core/src/application.rs

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@ use display::Display;
66
use git::Repository;
77
use input::{Event, EventHandler, EventReaderFn};
88
use parking_lot::Mutex;
9-
use runtime::{Runtime, Threadable};
9+
use runtime::{Runtime, ThreadStatuses, Threadable};
1010
use todo_file::TodoFile;
1111
use view::View;
1212

@@ -29,6 +29,7 @@ where ModuleProvider: module::ModuleProvider + Send + 'static
2929
_repository: Repository,
3030
process: Process<ModuleProvider>,
3131
threads: Option<Vec<Box<dyn Threadable>>>,
32+
thread_statuses: ThreadStatuses,
3233
}
3334

3435
impl<ModuleProvider> Application<ModuleProvider>
@@ -62,8 +63,8 @@ where ModuleProvider: module::ModuleProvider + Send + 'static
6263
.as_str(),
6364
);
6465

66+
let thread_statuses = ThreadStatuses::new();
6567
let mut threads: Vec<Box<dyn Threadable>> = vec![];
66-
let runtime = Runtime::new();
6768

6869
let input_threads = events::Thread::new(event_provider);
6970
let input_state = input_threads.state();
@@ -85,7 +86,7 @@ where ModuleProvider: module::ModuleProvider + Send + 'static
8586
input_state,
8687
view_state,
8788
search_state,
88-
runtime.statuses(),
89+
thread_statuses.clone(),
8990
);
9091
let process_threads = process::Thread::new(process.clone());
9192
threads.push(Box::new(process_threads));
@@ -95,6 +96,7 @@ where ModuleProvider: module::ModuleProvider + Send + 'static
9596
_repository: repository,
9697
process,
9798
threads: Some(threads),
99+
thread_statuses,
98100
})
99101
}
100102

@@ -107,7 +109,7 @@ where ModuleProvider: module::ModuleProvider + Send + 'static
107109
));
108110
};
109111

110-
let runtime = Runtime::new();
112+
let runtime = Runtime::new(self.thread_statuses.clone());
111113

112114
for thread in &mut threads {
113115
runtime.register(thread.as_mut());

src/runtime/src/installer.rs

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -16,10 +16,10 @@ pub struct Installer {
1616
}
1717

1818
impl Installer {
19-
pub(crate) fn new(sender: Sender<(String, Status)>) -> Self {
19+
pub(crate) fn new(thread_statuses: ThreadStatuses, sender: Sender<(String, Status)>) -> Self {
2020
Self {
2121
sender,
22-
thread_statuses: ThreadStatuses::new(),
22+
thread_statuses,
2323
ops: RefCell::new(HashMap::new()),
2424
}
2525
}
@@ -94,7 +94,7 @@ mod tests {
9494
#[test]
9595
fn test() {
9696
let (sender, _receiver) = unbounded();
97-
let installer = Installer::new(sender);
97+
let installer = Installer::new(ThreadStatuses::new(), sender);
9898

9999
let thread = Thread::new();
100100
thread.install(&installer);
@@ -109,7 +109,7 @@ mod tests {
109109
#[test]
110110
fn debug() {
111111
let (sender, _receiver) = unbounded();
112-
let installer = Installer::new(sender);
112+
let installer = Installer::new(ThreadStatuses::new(), sender);
113113
assert_eq!(
114114
format!("{installer:?}"),
115115
"Installer { sender: Sender { .. }, thread_statuses: ThreadStatuses { statuses: Mutex { data: {} } }, .. }"

src/runtime/src/runtime/mod.rs

Lines changed: 7 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -21,10 +21,9 @@ impl<'runtime> Runtime<'runtime> {
2121
/// Create a new instances of the `Runtime`.
2222
#[inline]
2323
#[must_use]
24-
pub fn new() -> Self {
24+
pub fn new(thread_statuses: ThreadStatuses) -> Self {
2525
let (sender, receiver) = unbounded();
2626

27-
let thread_statuses = ThreadStatuses::new();
2827
thread_statuses.register_thread(RUNTIME_THREAD_NAME, Status::Waiting);
2928

3029
Self {
@@ -54,7 +53,7 @@ impl<'runtime> Runtime<'runtime> {
5453
/// Returns and error if any of the threads registered to the runtime produce an error.
5554
#[inline]
5655
pub fn join(&self) -> Result<(), RuntimeError> {
57-
let installer = Installer::new(self.sender.clone());
56+
let installer = Installer::new(self.thread_statuses.clone(), self.sender.clone());
5857
{
5958
let threadables = self.threadables.lock();
6059
for threadable in threadables.iter() {
@@ -166,7 +165,7 @@ mod tests {
166165
}
167166
}
168167

169-
let runtime = Runtime::new();
168+
let runtime = Runtime::new(ThreadStatuses::new());
170169
let mut thread = Thread::new();
171170
runtime.register(&mut thread);
172171
runtime.join().unwrap();
@@ -223,7 +222,7 @@ mod tests {
223222
}
224223
}
225224

226-
let runtime = Runtime::new();
225+
let runtime = Runtime::new(ThreadStatuses::new());
227226
let mut thread1 = Thread1::new();
228227
let mut thread2 = Thread2::new();
229228
runtime.register(&mut thread1);
@@ -283,7 +282,7 @@ mod tests {
283282
}
284283
}
285284

286-
let runtime = Runtime::new();
285+
let runtime = Runtime::new(ThreadStatuses::new());
287286
let mut thread1 = Thread1::new();
288287
let mut thread2 = Thread2::new();
289288
runtime.register(&mut thread1);
@@ -344,7 +343,7 @@ mod tests {
344343
}
345344
}
346345

347-
let runtime = Runtime::new();
346+
let runtime = Runtime::new(ThreadStatuses::new());
348347
let mut thread1 = Thread1::new();
349348
let mut thread2 = Thread2::new();
350349
runtime.register(&mut thread1);
@@ -404,7 +403,7 @@ mod tests {
404403
}
405404
}
406405

407-
let runtime = Runtime::new();
406+
let runtime = Runtime::new(ThreadStatuses::new());
408407
let mut thread1 = Thread1::new();
409408
let mut thread2 = Thread2::new();
410409
runtime.register(&mut thread1);

src/runtime/src/testutils/mod.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -75,7 +75,7 @@ impl ThreadableTester {
7575
#[allow(clippy::missing_panics_doc)]
7676
pub fn start_threadable<Threadable: crate::Threadable>(&self, theadable: &Threadable, thread_name: &str) {
7777
self.ended.store(false, Ordering::Release);
78-
let installer = Installer::new(self.sender.clone());
78+
let installer = Installer::new(ThreadStatuses::new(), self.sender.clone());
7979
theadable.install(&installer);
8080
let mut ops = installer.into_ops();
8181
let op = ops.remove(thread_name).expect("Expected to find thead");

0 commit comments

Comments
 (0)