authorgravatar for kbutcher6200@gmail.comkprotty <kbutcher6200@gmail.com> 2019-11-07 16:33:25-06:00
committergravatar for kbutcher6200@gmail.comkprotty <kbutcher6200@gmail.com> 2019-11-07 16:33:25-06:00
log12e68cbeb636c920475b2420314c23de37689509
tree0e704118e01975303c8199009154d404892d709b
parentf41e58d015eec5fa595b4df8af3cf6a2b598bb02

pthread_sched_yield -> sched_yield


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;
158pub extern "c" fn pthread_attr_setstack(attr: *pthread_attr_t, stackaddr: *c_void, stacksize: usize) c_int;158pub extern "c" fn pthread_attr_setstack(attr: *pthread_attr_t, stackaddr: *c_void, stacksize: usize) c_int;
159pub extern "c" fn pthread_attr_destroy(attr: *pthread_attr_t) c_int;159pub extern "c" fn pthread_attr_destroy(attr: *pthread_attr_t) c_int;
160pub extern "c" fn pthread_self() pthread_t;160pub extern "c" fn pthread_self() pthread_t;
161pub extern "c" fn pthread_yield() c_int;
162pub extern "c" fn pthread_join(thread: pthread_t, arg_return: ?*?*c_void) c_int;161pub extern "c" fn pthread_join(thread: pthread_t, arg_return: ?*?*c_void) c_int;
163162
164pub extern "c" fn kqueue() c_int;163pub 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
204pub 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 }
105105
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}
31723172
3173pub fn yield() void {3173pub 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 {