mirror of
https://github.com/ziglang/zig.git
synced 2026-02-16 22:40:43 +00:00
pthread_sched_yield -> sched_yield
This commit is contained in:
parent
f41e58d015
commit
12e68cbeb6
@ -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;
|
||||
|
||||
@ -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()`
|
||||
|
||||
@ -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);
|
||||
}
|
||||
}
|
||||
|
||||
@ -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 {
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user