Skip to content

Commit

Permalink
Workaround schedule_write_op busy loop issue (moka-rs#412)
Browse files Browse the repository at this point in the history
Signed-off-by: Yilin Chen <sticnarf@gmail.com>
  • Loading branch information
sticnarf committed Apr 9, 2024
1 parent ae33f8d commit 8352623
Show file tree
Hide file tree
Showing 2 changed files with 4 additions and 0 deletions.
1 change: 1 addition & 0 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -55,6 +55,7 @@ smallvec = "1.8"
tagptr = "0.2"
thiserror = "1.0"
uuid = { version = "1.1", features = ["v4"] }
tokio = { version = "1", features = ["rt"] }

# Opt-out serde and stable_deref_trait features
# https://github.com/Manishearth/triomphe/pull/5
Expand Down
3 changes: 3 additions & 0 deletions src/future/base_cache.rs
Original file line number Diff line number Diff line change
Expand Up @@ -655,6 +655,9 @@ where

// We have got a `TrySendError::Full` above. Wait a moment and try again.

// Yield in case other `run_pending_tasks` cannot be scheduled by runtime.
tokio::task::yield_now().await;

if spin_loop_attempts < 4 {
spin_loop_attempts += 1;
// Wastes some CPU time with a hint to indicate to the CPU that we
Expand Down

0 comments on commit 8352623

Please sign in to comment.