Refactor FileCache to use Condvar for efficient waits

The `FileCache` now uses `std::sync::Condvar` to signal when files have
finished loading. This replaces the previous spin-wait mechanism,
significantly improving efficiency by allowing waiting threads to sleep
until explicitly woken up.

The `wait_for_load` method now blocks on the `Condvar`, and the
`insert_m1` and `insert_tick` methods call `notify_all` after updating
the cache and removing the loading guard. This ensures that all waiting
threads are woken up and can re-check the cache.

Additionally, `ensure_m1_loaded` and `ensure_tick_loaded` in
`DataServer` have been simplified to directly call `wait_for_load` when
another thread is already loading the file, removing the redundant
synchronous loading logic.
Refactor FileCache to use Condvar
This commit is contained in:
2026-03-29 20:47:49 +02:00
parent 38f657076b
commit c32cc0f49c
7 changed files with 435 additions and 47 deletions
+11
View File
@@ -53,11 +53,22 @@ struct Cli {
/// Emit the parsed source back as Myc code (round-trip test)
#[arg(long)]
emit: bool,
/// Path to tick data directory (overrides default /mnt/tickdata/Pepperstone)
#[arg(long)]
data_path: Option<PathBuf>,
}
fn main() {
let cli = Cli::parse();
// Initialize data server (before Environment::new so RTL has access)
if let Some(path) = &cli.data_path {
myc::ast::data_server::init_data_server(path);
} else {
myc::ast::data_server::init_default_data_server();
}
if cli.mcp {
if let Err(e) = myc::ast::mcp_server::run() {
eprintln!("MCP server error: {}", e);