-
Notifications
You must be signed in to change notification settings - Fork 1.4k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat: implement memory.atomic.notify,wait32,wait64
Added the parking_spot crate, which provides the needed registry for the operations. Signed-off-by: Harald Hoyer <[email protected]>
- Loading branch information
Showing
10 changed files
with
666 additions
and
38 deletions.
There are no files selected for viewing
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,15 @@ | ||
[package] | ||
name = "wasmtime-parking_spot" | ||
version.workspace = true | ||
authors.workspace = true | ||
license = "MIT OR Apache-2.0" | ||
repository = "https://github.com/bytecodealliance/wasmtime" | ||
keywords = ["thread", "park", "unpark", "parking", "lot", "wait", "notify"] | ||
categories = ["concurrency"] | ||
readme = "README.md" | ||
edition.workspace = true | ||
|
||
# See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html | ||
|
||
[dev-dependencies] | ||
once_cell = { workspace = true } |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,44 @@ | ||
# parking_spot | ||
|
||
Implements thread wait and notify primitives with `std::sync` primitives. | ||
|
||
This is a simplified version of the `parking_lot_core` crate. | ||
|
||
There are two main operations that can be performed: | ||
|
||
- *Parking* refers to suspending the thread while simultaneously enqueuing it | ||
on a queue keyed by some address. | ||
- *Unparking* refers to dequeuing a thread from a queue keyed by some address | ||
and resuming it. | ||
|
||
## Example | ||
|
||
```rust | ||
use std::sync::atomic::{AtomicU64, Ordering}; | ||
use std::sync::Arc; | ||
use std::thread; | ||
use parking_spot::ParkingSpot; | ||
|
||
let parking_spot: Arc<ParkingSpot> = Arc::new(ParkingSpot::default()); | ||
let atomic: Arc<AtomicU64> = Arc::new(AtomicU64::new(0)); | ||
let atomic_key = Arc::as_ptr(&atomic) as usize; | ||
|
||
let handle = { | ||
let parking_spot = parking_spot.clone(); | ||
let atomic = atomic.clone(); | ||
thread::spawn(move || { | ||
atomic.store(1, Ordering::Relaxed); | ||
parking_spot.unpark_all(atomic_key); | ||
parking_spot.park(atomic_key, || atomic.load(Ordering::SeqCst) == 1, None); | ||
assert_eq!(atomic.load(Ordering::SeqCst), 2); | ||
}) | ||
}; | ||
|
||
parking_spot.park(atomic_key, || atomic.load(Ordering::SeqCst) == 0, None); | ||
atomic.store(2, Ordering::Relaxed); | ||
parking_spot.unpark_all(atomic_key); | ||
|
||
handle.join().unwrap(); | ||
``` | ||
|
||
License: MIT OR Apache-2.0 |
Oops, something went wrong.