Skip to content
Snippets Groups Projects
Commit ee21e7d6 authored by Jorge Aparicio's avatar Jorge Aparicio
Browse files

make `Stim::write_*` methods take `&mut self` instead of `&self`

this prevents people from overlapping non-atomic write operations on the same stimulus port when
working with generators (cooperative tasks).

For example, with this change the following code won't compile

``` rust
let stim = &mut ITM.stim[0];
let a = || {
    loop {
        // ..
        for byte in b"Hello, world!".iter() {
            while !stim.is_fifo_ready() { yield }
            stim.write_u8(*byte);
        }
        // ..
    }
};

let b = || {
    loop {
        // ..
        for byte in b"The quick brown fox jumps over the lazy dog".iter() {
            while !stim.is_fifo_ready() { yield }
            stim.write_u8(*byte);
        }
        // ..
    }
};
```

A possible fix for the above code is to use different stimulus ports in each task (generator).
parent bdc7ca96
Branches
Tags
No related merge requests found
Loading
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment