| author | |
| committer | |
| log | 12e68cbeb636c920475b2420314c23de37689509 |
| tree | 0e704118e01975303c8199009154d404892d709b |
| parent | f41e58d015eec5fa595b4df8af3cf6a2b598bb02 |
4 files changed, 11 insertions(+), 10 deletions(-)
lib/std/c.zig+2-1| ... | @@ -158,7 +158,6 @@ pub extern "c" fn pthread_attr_init(attr: *pthread_attr_t) c_int; | ... | @@ -158,7 +158,6 @@ pub extern "c" fn pthread_attr_init(attr: *pthread_attr_t) c_int; |
| 158 | pub extern "c" fn pthread_attr_setstack(attr: *pthread_attr_t, stackaddr: *c_void, stacksize: usize) c_int; | 158 | pub extern "c" fn pthread_attr_setstack(attr: *pthread_attr_t, stackaddr: *c_void, stacksize: usize) c_int; |
| 159 | pub extern "c" fn pthread_attr_destroy(attr: *pthread_attr_t) c_int; | 159 | pub extern "c" fn pthread_attr_destroy(attr: *pthread_attr_t) c_int; |
| 160 | pub extern "c" fn pthread_self() pthread_t; | 160 | pub extern "c" fn pthread_self() pthread_t; |
| 161 | pub extern "c" fn pthread_yield() c_int; | ||
| 162 | pub extern "c" fn pthread_join(thread: pthread_t, arg_return: ?*?*c_void) c_int; | 161 | pub extern "c" fn pthread_join(thread: pthread_t, arg_return: ?*?*c_void) c_int; |
| 163 | 162 | ||
| 164 | pub extern "c" fn kqueue() c_int; | 163 | pub extern "c" fn kqueue() c_int; |
| ... | @@ -201,3 +200,5 @@ pub extern "c" fn dn_expand( | ... | @@ -201,3 +200,5 @@ pub extern "c" fn dn_expand( |
| 201 | exp_dn: [*]u8, | 200 | exp_dn: [*]u8, |
| 202 | length: c_int, | 201 | length: c_int, |
| 203 | ) c_int; | 202 | ) c_int; |
| 203 | |||
| 204 | pub extern "c" fn sched_yield() c_int; |
lib/std/mutex.zig+1-1| ... | @@ -100,7 +100,7 @@ else struct { | ... | @@ -100,7 +100,7 @@ else struct { |
| 100 | var value = @atomicLoad(u32, &self.state, .Monotonic); | 100 | var value = @atomicLoad(u32, &self.state, .Monotonic); |
| 101 | while (value == Unlocked) | 101 | while (value == Unlocked) |
| 102 | value = @cmpxchgWeak(u32, &self.state, Unlocked, state, .Acquire, .Monotonic) orelse return Held{ .mutex = self }; | 102 | value = @cmpxchgWeak(u32, &self.state, Unlocked, state, .Acquire, .Monotonic) orelse return Held{ .mutex = self }; |
| 103 | std.os.yield(); | 103 | std.os.sched_yield(); |
| 104 | } | 104 | } |
| 105 | 105 | ||
| 106 | // failed to acquire the lock, go to sleep until woken up by `Held.release()` | 106 | // failed to acquire the lock, go to sleep until woken up by `Held.release()` |
lib/std/os.zig+7-7| ... | @@ -3170,12 +3170,12 @@ pub fn dn_expand( | ... | @@ -3170,12 +3170,12 @@ pub fn dn_expand( |
| 3170 | return error.InvalidDnsPacket; | 3170 | return error.InvalidDnsPacket; |
| 3171 | } | 3171 | } |
| 3172 | 3172 | ||
| 3173 | pub fn yield() void { | 3173 | pub fn sched_yield() void { |
| 3174 | switch (builtin.os) { | 3174 | if (builtin.os == .windows) { |
| 3175 | .windows => _ = windows.kernel32.SwitchToThread(), | 3175 | _ = windows.kernel32.SwitchToThread(); |
| 3176 | .linux => _ = assert(linux.sched_yield() == 0), | 3176 | } else if (builtin.os == .linux and !builtin.link_libc) { |
| 3177 | else => if (builtin.link_libc) { | 3177 | assert(linux.sched_yield() == 0); |
| 3178 | assert(std.c.pthread_yield() == 0); | 3178 | } else if (builtin.link_libc) { |
| 3179 | }, | 3179 | assert(std.c.sched_yield() == 0); |
| 3180 | } | 3180 | } |
| 3181 | } | 3181 | } |
lib/std/spinlock.zig+1-1| ... | @@ -54,7 +54,7 @@ pub const SpinLock = struct { | ... | @@ -54,7 +54,7 @@ pub const SpinLock = struct { |
| 54 | if (self.iteration < 20) { | 54 | if (self.iteration < 20) { |
| 55 | SpinLock.yield(self.iteration); | 55 | SpinLock.yield(self.iteration); |
| 56 | } else if (self.iteration < 24) { | 56 | } else if (self.iteration < 24) { |
| 57 | os.yield(); | 57 | os.sched_yield(); |
| 58 | } else if (self.iteration < 26) { | 58 | } else if (self.iteration < 26) { |
| 59 | time.sleep(1 * time.millisecond); | 59 | time.sleep(1 * time.millisecond); |
| 60 | } else { | 60 | } else { |