Compare commits

..

6 commits

Author SHA1 Message Date
Jade Ellis
f36028b869
chore: Disable direnv's nix flake interfering with cargo cache
Some checks failed
Checks / Prefligit / prefligit (push) Failing after 1s
Release Docker Image / define-variables (push) Failing after 1s
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 / Format (push) Failing after 5s
Checks / Rust / Clippy (push) Failing after 33s
Checks / Rust / Cargo Test (push) Failing after 31s
2025-07-19 23:32:53 +01:00
Jade Ellis
5b1d47fa4d
feat: Enable hardware-lock-elision and deadlock_detection 2025-07-19 23:32:18 +01:00
Jade Ellis
6e226dbd39
refactor: Allow with_lock to return data and take an async closure 2025-07-19 23:30:31 +01:00
Jade Ellis
6cd132e207
refactor: Implement with_lock for lock_api 2025-07-19 22:30:41 +01:00
Jade Ellis
7c3dd210ac
refactor: Replace remaining std RwLocks 2025-07-19 22:20:26 +01:00
Jade Ellis
d37879730c
refactor: Replace remaining std Mutexes 2025-07-19 22:05:43 +01:00

View file

@ -1,8 +1,8 @@
#![cfg(feature = "console")] #![cfg(feature = "console")]
use std::{collections::VecDeque, sync::Arc}; use std::collections::VecDeque;
use conduwuit::{Server, SyncMutex, debug, defer, error, log, log::is_systemd_mode}; use conduwuit::{Arc, 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(); let mut worker_join = self.worker_join.lock().expect("locked");
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().take() else { let Some(worker_join) = self.worker_join.lock().expect("locked").take() else {
return; return;
}; };
@ -67,18 +67,22 @@ 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.lock().as_ref().map(JoinHandle::abort); self.worker_join
.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().take() { if let Some(input_abort) = self.input_abort.lock().expect("locked").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().take() { if let Some(command_abort) = self.command_abort.lock().expect("locked").take() {
debug!("Interrupting console command..."); debug!("Interrupting console command...");
command_abort.abort(); command_abort.abort();
} }
@ -113,7 +117,7 @@ impl Console {
} }
debug!("session ending"); debug!("session ending");
self.worker_join.lock().take(); self.worker_join.lock().expect("locked").take();
} }
async fn readline(self: &Arc<Self>) -> Result<ReadlineEvent, ReadlineError> { async fn readline(self: &Arc<Self>) -> Result<ReadlineEvent, ReadlineError> {
@ -128,9 +132,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().insert(abort); _ = self.input_abort.lock().expect("locked").insert(abort);
defer! {{ defer! {{
_ = self.input_abort.lock().take(); _ = self.input_abort.lock().expect("locked").take();
}} }}
let Ok(result) = future.await else { let Ok(result) = future.await else {
@ -151,9 +155,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().insert(abort); _ = self.command_abort.lock().expect("locked").insert(abort);
defer! {{ defer! {{
_ = self.command_abort.lock().take(); _ = self.command_abort.lock().expect("locked").take();
}} }}
_ = future.await; _ = future.await;
@ -177,15 +181,20 @@ impl Console {
} }
fn set_history(&self, readline: &mut Readline) { fn set_history(&self, readline: &mut Readline) {
self.history.lock().iter().rev().for_each(|entry| { self.history
readline .lock()
.add_history_entry(entry.clone()) .expect("locked")
.expect("added history entry"); .iter()
}); .rev()
.for_each(|entry| {
readline
.add_history_entry(entry.clone())
.expect("added history entry");
});
} }
fn add_history(&self, line: String) { fn add_history(&self, line: String) {
let mut history = self.history.lock(); let mut history = self.history.lock().expect("locked");
history.push_front(line); history.push_front(line);
history.truncate(HISTORY_LIMIT); history.truncate(HISTORY_LIMIT);
} }