pthread_sched_yield -> sched_yield

This commit is contained in:
kprotty 2019-11-07 16:33:25 -06:00
parent f41e58d015
commit 12e68cbeb6
4 changed files with 11 additions and 10 deletions

View File

@ -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;

View File

@ -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()`

View File

@ -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);
}
}

View File

@ -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 {