organize std lib concurrency primitives and add RwLock
* move concurrency primitives that always operate on kernel threads to the std.Thread namespace * remove std.SpinLock. Nobody should use this in a non-freestanding environment; the other primitives are always preferable. In freestanding, it will be necessary to put custom spin logic in there, so there are no use cases for a std lib version. * move some std lib files to the top level fields convention * add std.Thread.spinLoopHint * add std.Thread.Condition * add std.Thread.Semaphore * new implementation of std.Thread.Mutex for Windows and non-pthreads Linux * add std.Thread.RwLock Implementations provided by @kprotty
This commit is contained in:
@@ -50,7 +50,7 @@ pub const LineInfo = struct {
|
||||
}
|
||||
};
|
||||
|
||||
var stderr_mutex = std.Mutex{};
|
||||
var stderr_mutex = std.Thread.Mutex{};
|
||||
|
||||
/// Deprecated. Use `std.log` functions for logging or `std.debug.print` for
|
||||
/// "printf debugging".
|
||||
@@ -65,7 +65,7 @@ pub fn print(comptime fmt: []const u8, args: anytype) void {
|
||||
nosuspend stderr.print(fmt, args) catch return;
|
||||
}
|
||||
|
||||
pub fn getStderrMutex() *std.Mutex {
|
||||
pub fn getStderrMutex() *std.Thread.Mutex {
|
||||
return &stderr_mutex;
|
||||
}
|
||||
|
||||
@@ -235,7 +235,7 @@ pub fn panic(comptime format: []const u8, args: anytype) noreturn {
|
||||
var panicking: u8 = 0;
|
||||
|
||||
// Locked to avoid interleaving panic messages from multiple threads.
|
||||
var panic_mutex = std.Mutex{};
|
||||
var panic_mutex = std.Thread.Mutex{};
|
||||
|
||||
/// Counts how many times the panic handler is invoked by this thread.
|
||||
/// This is used to catch and handle panics triggered by the panic handler.
|
||||
@@ -280,7 +280,7 @@ pub fn panicExtra(trace: ?*const builtin.StackTrace, first_trace_addr: ?usize, c
|
||||
// and call abort()
|
||||
|
||||
// Sleep forever without hammering the CPU
|
||||
var event: std.StaticResetEvent = .{};
|
||||
var event: std.Thread.StaticResetEvent = .{};
|
||||
event.wait();
|
||||
unreachable;
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user