Switch from std::mpsc channels to crossbeam

This commit is contained in:
2026-01-02 12:44:50 +01:00
parent bbc9e0b9ff
commit 21fb6cbc8b
5 changed files with 74 additions and 14 deletions

57
Cargo.lock generated
View File

@@ -122,6 +122,62 @@ version = "1.0.4"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "b05b61dc5112cbb17e4b6cd61790d9845d13888356391624cbe7e41efeac1e75"
[[package]]
name = "crossbeam"
version = "0.8.4"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "1137cd7e7fc0fb5d3c5a8678be38ec56e819125d8d7907411fe24ccb943faca8"
dependencies = [
"crossbeam-channel",
"crossbeam-deque",
"crossbeam-epoch",
"crossbeam-queue",
"crossbeam-utils",
]
[[package]]
name = "crossbeam-channel"
version = "0.5.15"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "82b8f8f868b36967f9606790d1903570de9ceaf870a7bf9fbbd3016d636a2cb2"
dependencies = [
"crossbeam-utils",
]
[[package]]
name = "crossbeam-deque"
version = "0.8.6"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "9dd111b7b7f7d55b72c0a6ae361660ee5853c9af73f70c3c2ef6858b950e2e51"
dependencies = [
"crossbeam-epoch",
"crossbeam-utils",
]
[[package]]
name = "crossbeam-epoch"
version = "0.9.18"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "5b82ac4a3c2ca9c3460964f020e1402edd5753411d7737aa39c3714ad1b5420e"
dependencies = [
"crossbeam-utils",
]
[[package]]
name = "crossbeam-queue"
version = "0.3.12"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "0f58bbc28f91df819d0aa2a2c00cd19754769c2fad90579b3592b1c9ba7a3115"
dependencies = [
"crossbeam-utils",
]
[[package]]
name = "crossbeam-utils"
version = "0.8.21"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "d0a5c400df2834b80a4c3327b3aad3a4c4cd4de0629063962b03235697506a28"
[[package]]
name = "goblin"
version = "0.10.4"
@@ -281,6 +337,7 @@ version = "0.0.0"
dependencies = [
"anyhow",
"clap",
"crossbeam",
"goblin",
"int-enum",
"memmap2",

View File

@@ -6,6 +6,7 @@ edition = "2024"
[dependencies]
anyhow = "1.0.100"
clap = { version = "4.5.53", features = ["derive"] }
crossbeam = { version = "0.8.4", features = ["crossbeam-channel"] }
goblin = "0.10.4"
int-enum = "1.2.0"
memmap2 = "0.9.8"

View File

@@ -1,10 +1,10 @@
// Copyright (c) 2025 taitep
// Copyright (c) 2025-2026 taitep
// SPDX-License-Identifier: BSD-2-Clause
//
// This file is part of TRVE (https://gitea.taitep.se/taitep/trve)
// See LICENSE file in the project root for full license text.
use std::{collections::HashSet, sync::mpsc};
use std::collections::HashSet;
use crate::{
core::commands::CoreCmd,
@@ -19,13 +19,13 @@ pub struct Core {
pub(crate) x_regs: [u64; 32],
pub(crate) pc: u64,
pub(crate) mem: MemConfig,
command_stream: mpsc::Receiver<CoreCmd>,
command_stream: crossbeam::channel::Receiver<CoreCmd>,
}
pub mod commands;
impl Core {
pub fn new(mem: MemConfig, command_stream: mpsc::Receiver<CoreCmd>) -> Self {
pub fn new(mem: MemConfig, command_stream: crossbeam::channel::Receiver<CoreCmd>) -> Self {
Self {
x_regs: [0; 32],
pc: 0,
@@ -103,7 +103,10 @@ impl Core {
};
}
fn debug_loop(&mut self, dbg_stream: mpsc::Receiver<gdb::DebugCommand>) -> anyhow::Result<()> {
fn debug_loop(
&mut self,
dbg_stream: crossbeam::channel::Receiver<gdb::DebugCommand>,
) -> anyhow::Result<()> {
let mut breakpoints = HashSet::new();
loop {

View File

@@ -1,4 +1,4 @@
// Copyright (c) 2025 taitep
// Copyright (c) 2025-2026 taitep
// SPDX-License-Identifier: BSD-2-Clause
//
// This file is part of TRVE (https://gitea.taitep.se/taitep/trve)
@@ -7,7 +7,6 @@
use std::{
io::{self, BufRead, ErrorKind, Write},
net::{TcpListener, TcpStream},
sync::mpsc,
};
use crate::{
@@ -29,7 +28,7 @@ pub(crate) enum DebugCommand {
ExitDebugMode,
}
pub struct DebugStream(pub(crate) mpsc::Receiver<DebugCommand>);
pub struct DebugStream(pub(crate) crossbeam::channel::Receiver<DebugCommand>);
#[derive(Clone, Copy, Debug)]
pub(crate) enum StopReason {
@@ -68,13 +67,13 @@ pub(crate) struct RegsResponse {
pub pc: u64,
}
pub fn run_stub(cmd_sender: mpsc::Sender<CoreCmd>) {
pub fn run_stub(cmd_sender: crossbeam::channel::Sender<CoreCmd>) {
std::thread::spawn(move || {
let listener = TcpListener::bind("127.0.0.1:1234").expect("couldnt start tcp listener");
for stream_res in listener.incoming() {
if let Ok(stream) = stream_res {
let (dbg_tx, dbg_rx) = mpsc::channel();
let (dbg_tx, dbg_rx) = crossbeam::channel::bounded(16);
stream
.set_nonblocking(true)
@@ -92,7 +91,7 @@ pub fn run_stub(cmd_sender: mpsc::Sender<CoreCmd>) {
fn handle_gdb_connection(
gdb_stream: TcpStream,
dbg_tx: mpsc::Sender<DebugCommand>,
dbg_tx: crossbeam::channel::Sender<DebugCommand>,
) -> io::Result<()> {
eprintln!("gdb connected");
let mut reader = io::BufReader::new(gdb_stream.try_clone()?);
@@ -152,7 +151,7 @@ fn read_rsp_packet<R: BufRead>(reader: &mut R) -> io::Result<String> {
fn handle_packet<W: Write, R: BufRead>(
packet: &str,
writer: &mut W,
dbg_tx: &mpsc::Sender<DebugCommand>,
dbg_tx: &crossbeam::channel::Sender<DebugCommand>,
reader: &mut R,
) -> io::Result<()> {
writer.write_all(b"+")?;

View File

@@ -1,4 +1,4 @@
// Copyright (c) 2025 taitep
// Copyright (c) 2025-2026 taitep
// SPDX-License-Identifier: BSD-2-Clause
//
// This file is part of TRVE (https://gitea.taitep.se/taitep/trve)
@@ -48,7 +48,7 @@ fn main() -> Result<()> {
mmio_root,
};
let (cmd_sender, cmd_reciever) = std::sync::mpsc::channel();
let (cmd_sender, cmd_reciever) = crossbeam::channel::bounded(16);
gdb::run_stub(cmd_sender.clone());