Skip to content

Commit

Permalink
302 imix sleep underflow (#304)
Browse files Browse the repository at this point in the history
* Add check for unsigned underflow.

* Remove debug
  • Loading branch information
hulto authored Oct 6, 2023
1 parent bf08fd1 commit 0b820de
Showing 1 changed file with 6 additions and 3 deletions.
9 changes: 6 additions & 3 deletions implants/imix/src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -295,12 +295,15 @@ async fn main_loop(config_path: String, run_once: bool) -> Result<()> {
}
if debug { println!("[{}]: Queued task {}", (Utc::now().time() - start_time).num_milliseconds(), task.clone().id); }
}

// 3. Sleep till callback time
// time_to_wait - time_elapsed
let time_to_sleep = imix_config.callback_config.interval - loop_start_time.elapsed().as_secs();
let time_to_wait = imix_config.callback_config.interval as i64;
let time_elapsed = loop_start_time.elapsed().as_secs() as i64;
let mut time_to_sleep = time_to_wait - time_elapsed;
if time_to_sleep < 0 { time_to_sleep = 0; } // Control for unsigned underflow
if debug { println!("[{}]: Sleeping seconds {}", (Utc::now().time() - start_time).num_milliseconds(), time_to_sleep); }
// tokio::time::sleep(std::time::Duration::new(time_to_sleep, 24601)).await; // This seems to wait for other threads to finish.
std::thread::sleep(std::time::Duration::new(time_to_sleep, 24601)); // This just sleeps our thread.
std::thread::sleep(std::time::Duration::new(time_to_sleep as u64, 24601)); // This just sleeps our thread.

// :clap: :clap: make new map!
let mut running_exec_futures: HashMap<String, ExecTask> = HashMap::new();
Expand Down

0 comments on commit 0b820de

Please sign in to comment.