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