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:
Andrew Kelley
2021-01-14 20:41:37 -07:00
parent 2b0e3ee228
commit a9667b5a85
38 changed files with 1756 additions and 1272 deletions

View File

@@ -29,7 +29,7 @@ pub const Loop = struct {
fs_thread: *Thread,
fs_queue: std.atomic.Queue(Request),
fs_end_request: Request.Node,
fs_thread_wakeup: std.ResetEvent,
fs_thread_wakeup: std.Thread.ResetEvent,
/// For resources that have the same lifetime as the `Loop`.
/// This is only used by `Loop` for the thread pool and associated resources.
@@ -785,7 +785,7 @@ pub const Loop = struct {
timer: std.time.Timer,
waiters: Waiters,
thread: *std.Thread,
event: std.AutoResetEvent,
event: std.Thread.AutoResetEvent,
is_running: bool,
/// Initialize the delay queue by spawning the timer thread
@@ -796,7 +796,7 @@ pub const Loop = struct {
.waiters = DelayQueue.Waiters{
.entries = std.atomic.Queue(anyframe).init(),
},
.event = std.AutoResetEvent{},
.event = std.Thread.AutoResetEvent{},
.is_running = true,
// Must be last so that it can read the other state, such as `is_running`.
.thread = try std.Thread.spawn(self, DelayQueue.run),