| ... | ... | @@ -44,16 +44,17 @@ pub const SpinLock = struct { |
| 44 | 44 | } |
| 45 | 45 | } |
| 46 | 46 | |
| 47 | | const Backoff = struct { |
| 47 | /// Provides a method to incrementally yield longer each time its called. |
| 48 | pub const Backoff = struct { |
| 48 | 49 | iteration: usize, |
| 49 | 50 | |
| 50 | | fn init() @This() { |
| 51 | pub fn init() @This() { |
| 51 | 52 | return @This(){ .iteration = 0 }; |
| 52 | 53 | } |
| 53 | 54 | |
| 54 | | // Hybrid yielding from |
| 55 | | // http://www.1024cores.net/home/lock-free-algorithms/tricks/spinning |
| 56 | | fn yield(self: *@This()) void { |
| 55 | /// Hybrid yielding from |
| 56 | /// http://www.1024cores.net/home/lock-free-algorithms/tricks/spinning |
| 57 | pub fn yield(self: *@This()) void { |
| 57 | 58 | defer self.iteration +%= 1; |
| 58 | 59 | if (self.iteration < 10) { |
| 59 | 60 | yieldCpu(); |