diff options
| author | kprotty <kbutcher6200@gmail.com> | 2019-11-07 16:33:25 -0600 |
|---|---|---|
| committer | kprotty <kbutcher6200@gmail.com> | 2019-11-07 16:33:25 -0600 |
| commit | 12e68cbeb636c920475b2420314c23de37689509 (patch) | |
| tree | 0e704118e01975303c8199009154d404892d709b /lib/std | |
| parent | f41e58d015eec5fa595b4df8af3cf6a2b598bb02 (diff) | |
| download | zig-12e68cbeb636c920475b2420314c23de37689509.tar.gz zig-12e68cbeb636c920475b2420314c23de37689509.zip | |
pthread_sched_yield -> sched_yield
Diffstat (limited to 'lib/std')
| -rw-r--r-- | lib/std/c.zig | 3 | ||||
| -rw-r--r-- | lib/std/mutex.zig | 2 | ||||
| -rw-r--r-- | lib/std/os.zig | 14 | ||||
| -rw-r--r-- | lib/std/spinlock.zig | 2 |
4 files changed, 11 insertions, 10 deletions
diff --git a/lib/std/c.zig b/lib/std/c.zig index 201aa6b103..26fa71fe68 100644 --- a/lib/std/c.zig +++ b/lib/std/c.zig @@ -158,7 +158,6 @@ pub extern "c" fn pthread_attr_init(attr: *pthread_attr_t) c_int; pub extern "c" fn pthread_attr_setstack(attr: *pthread_attr_t, stackaddr: *c_void, stacksize: usize) c_int; pub extern "c" fn pthread_attr_destroy(attr: *pthread_attr_t) c_int; pub extern "c" fn pthread_self() pthread_t; -pub extern "c" fn pthread_yield() c_int; pub extern "c" fn pthread_join(thread: pthread_t, arg_return: ?*?*c_void) c_int; pub extern "c" fn kqueue() c_int; @@ -201,3 +200,5 @@ pub extern "c" fn dn_expand( exp_dn: [*]u8, length: c_int, ) c_int; + +pub extern "c" fn sched_yield() c_int; diff --git a/lib/std/mutex.zig b/lib/std/mutex.zig index 110f581f5e..5387bd4b15 100644 --- a/lib/std/mutex.zig +++ b/lib/std/mutex.zig @@ -100,7 +100,7 @@ else struct { var value = @atomicLoad(u32, &self.state, .Monotonic); while (value == Unlocked) value = @cmpxchgWeak(u32, &self.state, Unlocked, state, .Acquire, .Monotonic) orelse return Held{ .mutex = self }; - std.os.yield(); + std.os.sched_yield(); } // failed to acquire the lock, go to sleep until woken up by `Held.release()` diff --git a/lib/std/os.zig b/lib/std/os.zig index 72dd2a7196..2f19ee2a7d 100644 --- a/lib/std/os.zig +++ b/lib/std/os.zig @@ -3170,12 +3170,12 @@ pub fn dn_expand( return error.InvalidDnsPacket; } -pub fn yield() void { - switch (builtin.os) { - .windows => _ = windows.kernel32.SwitchToThread(), - .linux => _ = assert(linux.sched_yield() == 0), - else => if (builtin.link_libc) { - assert(std.c.pthread_yield() == 0); - }, +pub fn sched_yield() void { + if (builtin.os == .windows) { + _ = windows.kernel32.SwitchToThread(); + } else if (builtin.os == .linux and !builtin.link_libc) { + assert(linux.sched_yield() == 0); + } else if (builtin.link_libc) { + assert(std.c.sched_yield() == 0); } } diff --git a/lib/std/spinlock.zig b/lib/std/spinlock.zig index f69aae1bec..f2f2833875 100644 --- a/lib/std/spinlock.zig +++ b/lib/std/spinlock.zig @@ -54,7 +54,7 @@ pub const SpinLock = struct { if (self.iteration < 20) { SpinLock.yield(self.iteration); } else if (self.iteration < 24) { - os.yield(); + os.sched_yield(); } else if (self.iteration < 26) { time.sleep(1 * time.millisecond); } else { |
