| ... | @@ -75,7 +75,7 @@ else if (builtin.os == .windows) | ... | @@ -75,7 +75,7 @@ else if (builtin.os == .windows) |
| 75 | | 75 | |
| 76 | fn acquireSlow(self: *Mutex) Held { | 76 | fn acquireSlow(self: *Mutex) Held { |
| 77 | @setCold(true); | 77 | @setCold(true); |
| 78 | while (true) : (SpinLock.yield(1)) { | 78 | while (true) : (SpinLock.loopHint(1)) { |
| 79 | const waiters = @atomicLoad(u32, &self.waiters, .Monotonic); | 79 | const waiters = @atomicLoad(u32, &self.waiters, .Monotonic); |
| 80 | | 80 | |
| 81 | // try and take lock if unlocked | 81 | // try and take lock if unlocked |
| ... | @@ -99,7 +99,7 @@ else if (builtin.os == .windows) | ... | @@ -99,7 +99,7 @@ else if (builtin.os == .windows) |
| 99 | // unlock without a rmw/cmpxchg instruction | 99 | // unlock without a rmw/cmpxchg instruction |
| 100 | @atomicStore(u8, @ptrCast(*u8, &self.mutex.locked), 0, .Release); | 100 | @atomicStore(u8, @ptrCast(*u8, &self.mutex.locked), 0, .Release); |
| 101 | | 101 | |
| 102 | while (true) : (SpinLock.yield(1)) { | 102 | while (true) : (SpinLock.loopHint(1)) { |
| 103 | const waiters = @atomicLoad(u32, &self.mutex.waiters, .Monotonic); | 103 | const waiters = @atomicLoad(u32, &self.mutex.waiters, .Monotonic); |
| 104 | | 104 | |
| 105 | // no one is waiting | 105 | // no one is waiting |
| ... | @@ -142,10 +142,6 @@ else if (builtin.link_libc or builtin.os == .linux) | ... | @@ -142,10 +142,6 @@ else if (builtin.link_libc or builtin.os == .linux) |
| 142 | self.* = undefined; | 142 | self.* = undefined; |
| 143 | } | 143 | } |
| 144 | | 144 | |
| 145 | fn yield() void { | | |
| 146 | os.sched_yield() catch SpinLock.yield(30); | | |
| 147 | } | | |
| 148 | | | |
| 149 | pub fn tryAcquire(self: *Mutex) ?Held { | 145 | pub fn tryAcquire(self: *Mutex) ?Held { |
| 150 | if (@cmpxchgWeak(usize, &self.state, 0, MUTEX_LOCK, .Acquire, .Monotonic) != null) | 146 | if (@cmpxchgWeak(usize, &self.state, 0, MUTEX_LOCK, .Acquire, .Monotonic) != null) |
| 151 | return null; | 147 | return null; |
| ... | @@ -175,7 +171,7 @@ else if (builtin.link_libc or builtin.os == .linux) | ... | @@ -175,7 +171,7 @@ else if (builtin.link_libc or builtin.os == .linux) |
| 175 | } else if (state & QUEUE_MASK == 0) { | 171 | } else if (state & QUEUE_MASK == 0) { |
| 176 | break; | 172 | break; |
| 177 | } | 173 | } |
| 178 | yield(); | 174 | SpinLock.yield(); |
| 179 | state = @atomicLoad(usize, &self.state, .Monotonic); | 175 | state = @atomicLoad(usize, &self.state, .Monotonic); |
| 180 | } | 176 | } |
| 181 | | 177 | |
| ... | @@ -198,7 +194,7 @@ else if (builtin.link_libc or builtin.os == .linux) | ... | @@ -198,7 +194,7 @@ else if (builtin.link_libc or builtin.os == .linux) |
| 198 | break; | 194 | break; |
| 199 | }; | 195 | }; |
| 200 | } | 196 | } |
| 201 | yield(); | 197 | SpinLock.yield(); |
| 202 | state = @atomicLoad(usize, &self.state, .Monotonic); | 198 | state = @atomicLoad(usize, &self.state, .Monotonic); |
| 203 | } | 199 | } |
| 204 | } | 200 | } |
| ... | @@ -225,7 +221,7 @@ else if (builtin.link_libc or builtin.os == .linux) | ... | @@ -225,7 +221,7 @@ else if (builtin.link_libc or builtin.os == .linux) |
| 225 | // try and lock the LFIO queue to pop a node off, | 221 | // try and lock the LFIO queue to pop a node off, |
| 226 | // stopping altogether if its already locked or the queue is empty | 222 | // stopping altogether if its already locked or the queue is empty |
| 227 | var state = @atomicLoad(usize, &self.state, .Monotonic); | 223 | var state = @atomicLoad(usize, &self.state, .Monotonic); |
| 228 | while (true) : (std.SpinLock.yield(1)) { | 224 | while (true) : (SpinLock.loopHint(1)) { |
| 229 | if (state & QUEUE_LOCK != 0 or state & QUEUE_MASK == 0) | 225 | if (state & QUEUE_LOCK != 0 or state & QUEUE_MASK == 0) |
| 230 | return; | 226 | return; |
| 231 | state = @cmpxchgWeak(usize, &self.state, state, state | QUEUE_LOCK, .Acquire, .Monotonic) orelse break; | 227 | state = @cmpxchgWeak(usize, &self.state, state, state | QUEUE_LOCK, .Acquire, .Monotonic) orelse break; |
| ... | @@ -234,7 +230,7 @@ else if (builtin.link_libc or builtin.os == .linux) | ... | @@ -234,7 +230,7 @@ else if (builtin.link_libc or builtin.os == .linux) |
| 234 | // acquired the QUEUE_LOCK, try and pop a node to wake it. | 230 | // acquired the QUEUE_LOCK, try and pop a node to wake it. |
| 235 | // if the mutex is locked, then unset QUEUE_LOCK and let | 231 | // if the mutex is locked, then unset QUEUE_LOCK and let |
| 236 | // the thread who holds the mutex do the wake-up on unlock() | 232 | // the thread who holds the mutex do the wake-up on unlock() |
| 237 | while (true) : (std.SpinLock.yield(1)) { | 233 | while (true) : (SpinLock.loopHint(1)) { |
| 238 | if ((state & MUTEX_LOCK) != 0) { | 234 | if ((state & MUTEX_LOCK) != 0) { |
| 239 | state = @cmpxchgWeak(usize, &self.state, state, state & ~QUEUE_LOCK, .Release, .Acquire) orelse return; | 235 | state = @cmpxchgWeak(usize, &self.state, state, state & ~QUEUE_LOCK, .Release, .Acquire) orelse return; |
| 240 | } else { | 236 | } else { |