Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Rework synchronization primitives - Futex edition #8084

Closed
wants to merge 29 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
29 commits
Select commit Hold shift + click to select a range
f1c96bf
start on futex primitives
kprotty Jan 22, 2021
05391af
previous OS updates from another branch
kprotty Jan 22, 2021
372c8a0
zig fmt
kprotty Jan 22, 2021
136c9c9
more futex stuff
kprotty Jan 22, 2021
a712175
generic futex impl
kprotty Jan 22, 2021
e4e51f0
more work on futex
kprotty Jan 23, 2021
c1ad361
test cases pass on linux
kprotty Jan 23, 2021
0910ca8
std.Thread.* references std.sync + event fixes
kprotty Jan 23, 2021
b4eb55e
integrate sync.futex.event with event loop
kprotty Jan 23, 2021
bdd36e4
sync.futex.event comments
kprotty Jan 23, 2021
8c1feab
zig fmt
kprotty Jan 23, 2021
57f2239
fixing generic futex impl
kprotty Jan 25, 2021
7c47cca
Futex notify* -> wake() + window futex.os
kprotty Jan 25, 2021
afe3fa1
zig fmt + fix windows NT futex backend
kprotty Jan 25, 2021
a54aa65
optimize sync.primitives.Mutex
kprotty Jan 25, 2021
f8fb07b
fix evented tests
kprotty Jan 25, 2021
b198b22
optimize ResetEvent to not call Futex as often
kprotty Jan 25, 2021
f564d40
WaitGroup use usize > u32
kprotty Jan 25, 2021
381a0de
Semaphore + WaitGroup simplifications
kprotty Jan 25, 2021
3723501
Trying to retro-fit stuff into the current std.event.Loop
kprotty Jan 25, 2021
fb4bd82
change when WaitBucket.waiters is updated
kprotty Jan 25, 2021
75f0d05
Condvar debug impl
kprotty Jan 26, 2021
9a0bdc0
fix bits type incompatibility with macOS
kristoff-it Jan 26, 2021
149127f
tests for Once sync primitive
kristoff-it Jan 26, 2021
637626e
slight cleanup + Condvar test
kprotty Jan 28, 2021
f386d74
actually perform Condvar tests
kprotty Jan 28, 2021
94e6c2f
add tests for Semaphore
kprotty Jan 28, 2021
c4c9cb4
initial RwLock implementation
kprotty Jan 28, 2021
73f0dc4
zig fmt
kprotty Feb 27, 2021
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
20 changes: 15 additions & 5 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -492,6 +492,21 @@ set(ZIG_STAGE2_SOURCES
"${CMAKE_SOURCE_DIR}/lib/std/special/compiler_rt/umodti3.zig"
"${CMAKE_SOURCE_DIR}/lib/std/start.zig"
"${CMAKE_SOURCE_DIR}/lib/std/std.zig"
"${CMAKE_SOURCE_DIR}/lib/std/sync.zig"
"${CMAKE_SOURCE_DIR}/lib/std/sync/atomic.zig"
"${CMAKE_SOURCE_DIR}/lib/std/sync/futex.zig"
"${CMAKE_SOURCE_DIR}/lib/std/sync/primitives.zig"
"${CMAKE_SOURCE_DIR}/lib/std/sync/futex/event.zig"
"${CMAKE_SOURCE_DIR}/lib/std/sync/futex/generic.zig"
"${CMAKE_SOURCE_DIR}/lib/std/sync/futex/os.zig"
"${CMAKE_SOURCE_DIR}/lib/std/sync/futex/spin.zig"
"${CMAKE_SOURCE_DIR}/lib/std/sync/primitives/Condvar.zig"
"${CMAKE_SOURCE_DIR}/lib/std/sync/primitives/Mutex.zig"
"${CMAKE_SOURCE_DIR}/lib/std/sync/primitives/Once.zig"
"${CMAKE_SOURCE_DIR}/lib/std/sync/primitives/ResetEvent.zig"
"${CMAKE_SOURCE_DIR}/lib/std/sync/primitives/RwLock.zig"
"${CMAKE_SOURCE_DIR}/lib/std/sync/primitives/Semaphore.zig"
"${CMAKE_SOURCE_DIR}/lib/std/sync/primitives/WaitGroup.zig"
"${CMAKE_SOURCE_DIR}/lib/std/target.zig"
"${CMAKE_SOURCE_DIR}/lib/std/target/aarch64.zig"
"${CMAKE_SOURCE_DIR}/lib/std/target/amdgpu.zig"
Expand All @@ -509,10 +524,6 @@ set(ZIG_STAGE2_SOURCES
"${CMAKE_SOURCE_DIR}/lib/std/target/wasm.zig"
"${CMAKE_SOURCE_DIR}/lib/std/target/x86.zig"
"${CMAKE_SOURCE_DIR}/lib/std/Thread.zig"
"${CMAKE_SOURCE_DIR}/lib/std/Thread/AutoResetEvent.zig"
"${CMAKE_SOURCE_DIR}/lib/std/Thread/Mutex.zig"
"${CMAKE_SOURCE_DIR}/lib/std/Thread/ResetEvent.zig"
"${CMAKE_SOURCE_DIR}/lib/std/Thread/StaticResetEvent.zig"
"${CMAKE_SOURCE_DIR}/lib/std/time.zig"
"${CMAKE_SOURCE_DIR}/lib/std/unicode.zig"
"${CMAKE_SOURCE_DIR}/lib/std/zig.zig"
Expand All @@ -532,7 +543,6 @@ set(ZIG_STAGE2_SOURCES
"${CMAKE_SOURCE_DIR}/src/RangeSet.zig"
"${CMAKE_SOURCE_DIR}/src/ThreadPool.zig"
"${CMAKE_SOURCE_DIR}/src/TypedValue.zig"
"${CMAKE_SOURCE_DIR}/src/WaitGroup.zig"
"${CMAKE_SOURCE_DIR}/src/astgen.zig"
"${CMAKE_SOURCE_DIR}/src/clang.zig"
"${CMAKE_SOURCE_DIR}/src/clang_options.zig"
Expand Down
30 changes: 17 additions & 13 deletions lib/std/Thread.zig
Original file line number Diff line number Diff line change
Expand Up @@ -10,12 +10,7 @@

data: Data,

pub const AutoResetEvent = @import("Thread/AutoResetEvent.zig");
pub const ResetEvent = @import("Thread/ResetEvent.zig");
pub const StaticResetEvent = @import("Thread/StaticResetEvent.zig");
pub const Mutex = @import("Thread/Mutex.zig");
pub const Semaphore = @import("Thread/Semaphore.zig");
pub const Condition = @import("Thread/Condition.zig");
pub usingnamespace std.sync.primitives.with(std.sync.futex.os);

pub const use_pthreads = std.Target.current.os.tag != .windows and builtin.link_libc;

Expand Down Expand Up @@ -70,8 +65,16 @@ else switch (std.Target.current.os.tag) {
/// Signals the processor that it is inside a busy-wait spin-loop ("spin lock").
pub fn spinLoopHint() void {
switch (std.Target.current.cpu.arch) {
.i386, .x86_64 => asm volatile ("pause" ::: "memory"),
.arm, .aarch64 => asm volatile ("yield" ::: "memory"),
.i386, .x86_64 => asm volatile ("pause"
:
:
: "memory"
),
.arm, .aarch64 => asm volatile ("yield"
:
:
: "memory"
),
else => {},
}
}
Expand All @@ -82,11 +85,12 @@ pub fn spinLoopHint() void {
pub fn getCurrentId() Id {
if (use_pthreads) {
return c.pthread_self();
} else return switch (std.Target.current.os.tag) {
.linux => os.linux.gettid(),
.windows => windows.kernel32.GetCurrentThreadId(),
else => @compileError("Unsupported OS"),
};
} else
return switch (std.Target.current.os.tag) {
.linux => os.linux.gettid(),
.windows => windows.kernel32.GetCurrentThreadId(),
else => @compileError("Unsupported OS"),
};
}

/// Returns the handle of this thread.
Expand Down
228 changes: 0 additions & 228 deletions lib/std/Thread/AutoResetEvent.zig

This file was deleted.

Loading