authorgravatar for kbutcher6200@gmail.comkprotty <kbutcher6200@gmail.com> 2019-11-05 13:43:17-06:00
committergravatar for kbutcher6200@gmail.comkprotty <kbutcher6200@gmail.com> 2019-11-05 13:43:17-06:00
log14209cf615f2c218319e0c7a567484caf328dfe6
treefb9e59febe0c665c46b325f961f4da570fbd22df
parent84e370d0b2ce2240356ebd0a6007aec8620dfa10

make SpinLock.Backoff pub


1 files changed, 6 insertions(+), 5 deletions(-)

lib/std/spinlock.zig+6-5
......@@ -44,16 +44,17 @@ pub const SpinLock = struct {
4444 }
4545 }
4646
47 const Backoff = struct {
47 /// Provides a method to incrementally yield longer each time its called.
48 pub const Backoff = struct {
4849 iteration: usize,
4950
50 fn init() @This() {
51 pub fn init() @This() {
5152 return @This(){ .iteration = 0 };
5253 }
5354
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 {
5758 defer self.iteration +%= 1;
5859 if (self.iteration < 10) {
5960 yieldCpu();