mirror of
https://github.com/ziglang/zig.git
synced 2026-02-13 12:59:04 +00:00
make SpinLock.Backoff pub
This commit is contained in:
parent
84e370d0b2
commit
14209cf615
@ -44,16 +44,17 @@ pub const SpinLock = struct {
|
||||
}
|
||||
}
|
||||
|
||||
const Backoff = struct {
|
||||
/// Provides a method to incrementally yield longer each time its called.
|
||||
pub const Backoff = struct {
|
||||
iteration: usize,
|
||||
|
||||
fn init() @This() {
|
||||
pub fn init() @This() {
|
||||
return @This(){ .iteration = 0 };
|
||||
}
|
||||
|
||||
// Hybrid yielding from
|
||||
// http://www.1024cores.net/home/lock-free-algorithms/tricks/spinning
|
||||
fn yield(self: *@This()) void {
|
||||
/// Hybrid yielding from
|
||||
/// http://www.1024cores.net/home/lock-free-algorithms/tricks/spinning
|
||||
pub fn yield(self: *@This()) void {
|
||||
defer self.iteration +%= 1;
|
||||
if (self.iteration < 10) {
|
||||
yieldCpu();
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user