Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

chore: name std threads #8475

Merged
merged 1 commit into from
May 29, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 8 additions & 2 deletions crates/cli/runner/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -58,7 +58,10 @@ impl CliRunner {
// drop the tokio runtime on a separate thread because drop blocks until its pools
// (including blocking pool) are shutdown. In other words `drop(tokio_runtime)` would block
// the current thread but we want to exit right away.
std::thread::spawn(move || drop(tokio_runtime));
std::thread::Builder::new()
.name("tokio-runtime-shutdown".to_string())
.spawn(move || drop(tokio_runtime))
.unwrap();

command_res
}
Expand Down Expand Up @@ -92,7 +95,10 @@ impl CliRunner {
// drop the tokio runtime on a separate thread because drop blocks until its pools
// (including blocking pool) are shutdown. In other words `drop(tokio_runtime)` would block
// the current thread but we want to exit right away.
std::thread::spawn(move || drop(tokio_runtime));
std::thread::Builder::new()
.name("tokio-runtime-shutdown".to_string())
.spawn(move || drop(tokio_runtime))
.unwrap();

Ok(())
}
Expand Down
22 changes: 13 additions & 9 deletions crates/storage/libmdbx-rs/src/txn_manager.rs
Original file line number Diff line number Diff line change
Expand Up @@ -45,14 +45,14 @@ impl TxnManager {
txn_manager
}

/// Spawns a new thread with [std::thread::spawn] that listens to incoming [TxnManagerMessage]
/// messages, executes an FFI function, and returns the result on the provided channel.
/// Spawns a new [std::thread] that listens to incoming [TxnManagerMessage] messages, executes
/// an FFI function, and returns the result on the provided channel.
///
/// - [TxnManagerMessage::Begin] opens a new transaction with [ffi::mdbx_txn_begin_ex]
/// - [TxnManagerMessage::Abort] aborts a transaction with [ffi::mdbx_txn_abort]
/// - [TxnManagerMessage::Commit] commits a transaction with [ffi::mdbx_txn_commit_ex]
fn start_message_listener(&self, env: EnvPtr, rx: Receiver<TxnManagerMessage>) {
std::thread::spawn(move || {
let task = move || {
#[allow(clippy::redundant_locals)]
let env = env;
loop {
Expand Down Expand Up @@ -90,7 +90,8 @@ impl TxnManager {
Err(_) => return,
}
}
});
};
std::thread::Builder::new().name("mbdx-rs-txn-manager".to_string()).spawn(task).unwrap();
}

pub(crate) fn send_message(&self, message: TxnManagerMessage) {
Expand Down Expand Up @@ -198,11 +199,10 @@ mod read_transactions {
self.timed_out_not_aborted.len()
}

/// Spawns a new thread with [std::thread::spawn] that monitors the list of active read
/// transactions and timeouts those that are open for longer than
/// `ReadTransactions.max_duration`.
/// Spawns a new [std::thread] that monitors the list of active read transactions and
/// timeouts those that are open for longer than `ReadTransactions.max_duration`.
pub(super) fn start_monitor(self: Arc<Self>) {
std::thread::spawn(move || {
let task = move || {
let mut timed_out_active = Vec::new();

loop {
Expand Down Expand Up @@ -295,7 +295,11 @@ mod read_transactions {
READ_TRANSACTIONS_CHECK_INTERVAL.min(duration_until_closest_deadline),
);
}
});
};
std::thread::Builder::new()
.name("mdbx-rs-read-tx-timeouts".to_string())
.spawn(task)
.unwrap();
}
}

Expand Down
Loading