Compare commits

..

6 commits

Author SHA1 Message Date
Jade Ellis
394382884d
chore: Disable direnv's nix flake interfering with cargo cache
Some checks failed
Checks / Prefligit / prefligit (push) Failing after 24s
Release Docker Image / define-variables (push) Failing after 22s
Checks / Rust / Format (push) Failing after 21s
Release Docker Image / build-image (linux/amd64, release, linux-amd64, base) (push) Has been skipped
Release Docker Image / build-image (linux/arm64, release, linux-arm64, base) (push) Has been skipped
Release Docker Image / merge (push) Has been skipped
Checks / Rust / Clippy (push) Failing after 30s
Checks / Rust / Cargo Test (push) Failing after 32s
2025-07-20 01:20:25 +01:00
Jade Ellis
2e1575863a
feat: Enable hardware-lock-elision and deadlock_detection 2025-07-20 01:20:25 +01:00
Jade Ellis
547d4d9f88
refactor: Allow with_lock to return data and take an async closure 2025-07-20 01:20:02 +01:00
Jade Ellis
b3a9cff497
refactor: Implement with_lock for lock_api 2025-07-20 01:20:02 +01:00
Jade Ellis
ea8e80b2b7
refactor: Replace remaining std RwLocks 2025-07-20 01:20:02 +01:00
Jade Ellis
a047cb600e
refactor: Replace remaining std Mutexes 2025-07-20 01:20:02 +01:00

View file

@ -1,8 +1,8 @@
#![cfg(feature = "console")] #![cfg(feature = "console")]
use std::collections::VecDeque; use std::{collections::VecDeque, sync::Arc};
use conduwuit::{Arc, Server, SyncMutex, debug, defer, error, log, log::is_systemd_mode}; use conduwuit::{Server, SyncMutex, debug, defer, error, log, log::is_systemd_mode};
use futures::future::{AbortHandle, Abortable}; use futures::future::{AbortHandle, Abortable};
use ruma::events::room::message::RoomMessageEventContent; use ruma::events::room::message::RoomMessageEventContent;
use rustyline_async::{Readline, ReadlineError, ReadlineEvent}; use rustyline_async::{Readline, ReadlineError, ReadlineEvent};
@ -47,7 +47,7 @@ impl Console {
} }
pub async fn start(self: &Arc<Self>) { pub async fn start(self: &Arc<Self>) {
let mut worker_join = self.worker_join.lock().expect("locked"); let mut worker_join = self.worker_join.lock();
if worker_join.is_none() { if worker_join.is_none() {
let self_ = Arc::clone(self); let self_ = Arc::clone(self);
_ = worker_join.insert(self.server.runtime().spawn(self_.worker())); _ = worker_join.insert(self.server.runtime().spawn(self_.worker()));
@ -57,7 +57,7 @@ impl Console {
pub async fn close(self: &Arc<Self>) { pub async fn close(self: &Arc<Self>) {
self.interrupt(); self.interrupt();
let Some(worker_join) = self.worker_join.lock().expect("locked").take() else { let Some(worker_join) = self.worker_join.lock().take() else {
return; return;
}; };
@ -67,22 +67,18 @@ impl Console {
pub fn interrupt(self: &Arc<Self>) { pub fn interrupt(self: &Arc<Self>) {
self.interrupt_command(); self.interrupt_command();
self.interrupt_readline(); self.interrupt_readline();
self.worker_join self.worker_join.lock().as_ref().map(JoinHandle::abort);
.lock()
.expect("locked")
.as_ref()
.map(JoinHandle::abort);
} }
pub fn interrupt_readline(self: &Arc<Self>) { pub fn interrupt_readline(self: &Arc<Self>) {
if let Some(input_abort) = self.input_abort.lock().expect("locked").take() { if let Some(input_abort) = self.input_abort.lock().take() {
debug!("Interrupting console readline..."); debug!("Interrupting console readline...");
input_abort.abort(); input_abort.abort();
} }
} }
pub fn interrupt_command(self: &Arc<Self>) { pub fn interrupt_command(self: &Arc<Self>) {
if let Some(command_abort) = self.command_abort.lock().expect("locked").take() { if let Some(command_abort) = self.command_abort.lock().take() {
debug!("Interrupting console command..."); debug!("Interrupting console command...");
command_abort.abort(); command_abort.abort();
} }
@ -117,7 +113,7 @@ impl Console {
} }
debug!("session ending"); debug!("session ending");
self.worker_join.lock().expect("locked").take(); self.worker_join.lock().take();
} }
async fn readline(self: &Arc<Self>) -> Result<ReadlineEvent, ReadlineError> { async fn readline(self: &Arc<Self>) -> Result<ReadlineEvent, ReadlineError> {
@ -132,9 +128,9 @@ impl Console {
let (abort, abort_reg) = AbortHandle::new_pair(); let (abort, abort_reg) = AbortHandle::new_pair();
let future = Abortable::new(future, abort_reg); let future = Abortable::new(future, abort_reg);
_ = self.input_abort.lock().expect("locked").insert(abort); _ = self.input_abort.lock().insert(abort);
defer! {{ defer! {{
_ = self.input_abort.lock().expect("locked").take(); _ = self.input_abort.lock().take();
}} }}
let Ok(result) = future.await else { let Ok(result) = future.await else {
@ -155,9 +151,9 @@ impl Console {
let (abort, abort_reg) = AbortHandle::new_pair(); let (abort, abort_reg) = AbortHandle::new_pair();
let future = Abortable::new(future, abort_reg); let future = Abortable::new(future, abort_reg);
_ = self.command_abort.lock().expect("locked").insert(abort); _ = self.command_abort.lock().insert(abort);
defer! {{ defer! {{
_ = self.command_abort.lock().expect("locked").take(); _ = self.command_abort.lock().take();
}} }}
_ = future.await; _ = future.await;
@ -181,12 +177,7 @@ impl Console {
} }
fn set_history(&self, readline: &mut Readline) { fn set_history(&self, readline: &mut Readline) {
self.history self.history.lock().iter().rev().for_each(|entry| {
.lock()
.expect("locked")
.iter()
.rev()
.for_each(|entry| {
readline readline
.add_history_entry(entry.clone()) .add_history_entry(entry.clone())
.expect("added history entry"); .expect("added history entry");
@ -194,7 +185,7 @@ impl Console {
} }
fn add_history(&self, line: String) { fn add_history(&self, line: String) {
let mut history = self.history.lock().expect("locked"); let mut history = self.history.lock();
history.push_front(line); history.push_front(line);
history.truncate(HISTORY_LIMIT); history.truncate(HISTORY_LIMIT);
} }