aboutsummaryrefslogtreecommitdiff
path: root/azalea/examples/testbot
diff options
context:
space:
mode:
authorEightFactorial <29801334+EightFactorial@users.noreply.github.com>2024-12-10 14:37:35 -0800
committerGitHub <noreply@github.com>2024-12-10 16:37:35 -0600
commit2feef494718009dbcb5c62ef1e58c84c36e8bcbf (patch)
tree8f2ebbc219c14ca383d3b392c3d03aa90c9bf8ac /azalea/examples/testbot
parent07109964ad8486a9d4caee430ccadf7f7fc3d648 (diff)
downloadazalea-drasl-2feef494718009dbcb5c62ef1e58c84c36e8bcbf.tar.xz
Disable the `deadlock_detection` feature by default (#195)
* Disable the `deadlock_detection` feature by default Fixes conflicts with any packages that enable parking_lot's `send_guard` feature * move testbot deadlock detection to a function and add additional comments --------- Co-authored-by: mat <git@matdoes.dev>
Diffstat (limited to 'azalea/examples/testbot')
-rw-r--r--azalea/examples/testbot/main.rs51
1 files changed, 26 insertions, 25 deletions
diff --git a/azalea/examples/testbot/main.rs b/azalea/examples/testbot/main.rs
index e7d68d5e..9c8d1085 100644
--- a/azalea/examples/testbot/main.rs
+++ b/azalea/examples/testbot/main.rs
@@ -14,8 +14,8 @@
mod commands;
pub mod killaura;
-use std::sync::Arc;
use std::time::Duration;
+use std::{sync::Arc, thread};
use azalea::brigadier::command_dispatcher::CommandDispatcher;
use azalea::ecs::prelude::*;
@@ -37,30 +37,7 @@ const PATHFINDER_DEBUG_PARTICLES: bool = false;
#[tokio::main]
async fn main() {
- {
- use std::thread;
- use std::time::Duration;
-
- use parking_lot::deadlock;
-
- // Create a background thread which checks for deadlocks every 10s
- thread::spawn(move || loop {
- thread::sleep(Duration::from_secs(10));
- let deadlocks = deadlock::check_deadlock();
- if deadlocks.is_empty() {
- continue;
- }
-
- println!("{} deadlocks detected", deadlocks.len());
- for (i, threads) in deadlocks.iter().enumerate() {
- println!("Deadlock #{i}");
- for t in threads {
- println!("Thread Id {:#?}", t.thread_id());
- println!("{:#?}", t.backtrace());
- }
- }
- });
- }
+ thread::spawn(deadlock_detection_thread);
let account = Account::offline(USERNAME);
@@ -85,6 +62,30 @@ async fn main() {
.unwrap();
}
+/// Runs a loop that checks for deadlocks every 10 seconds.
+///
+/// Note that this requires the `deadlock_detection` parking_lot feature to be
+/// enabled, which is only enabled in azalea by default when running in debug
+/// mode.
+fn deadlock_detection_thread() {
+ loop {
+ thread::sleep(Duration::from_secs(10));
+ let deadlocks = parking_lot::deadlock::check_deadlock();
+ if deadlocks.is_empty() {
+ continue;
+ }
+
+ println!("{} deadlocks detected", deadlocks.len());
+ for (i, threads) in deadlocks.iter().enumerate() {
+ println!("Deadlock #{i}");
+ for t in threads {
+ println!("Thread Id {:#?}", t.thread_id());
+ println!("{:#?}", t.backtrace());
+ }
+ }
+ }
+}
+
#[derive(Clone, Copy, Debug, PartialEq, Eq, Default)]
pub enum BotTask {
#[default]