| ... | @@ -69,19 +69,26 @@ pub const Id = if (InternPool.single_threaded) enum { | ... | @@ -69,19 +69,26 @@ pub const Id = if (InternPool.single_threaded) enum { |
| 69 | /// will likely involve significant changes to the `InternPool` implementation. | 69 | /// will likely involve significant changes to the `InternPool` implementation. |
| 70 | var available_tids: std.ArrayList(Id) = .empty; | 70 | var available_tids: std.ArrayList(Id) = .empty; |
| 71 | threadlocal var recursive_depth: usize = 0; | 71 | threadlocal var recursive_depth: usize = 0; |
| 72 | threadlocal var recursive_tid: Id = .main; | 72 | threadlocal var recursive_tid: Id = undefined; |
| 73 | | 73 | |
| 74 | pub fn allocate(arena: Allocator, n: usize) Allocator.Error!void { | 74 | pub fn allocate(arena: Allocator, n: usize) Allocator.Error!void { |
| 75 | assert(available_tids.items.len == 0); | 75 | assert(available_tids.items.len == 0); |
| 76 | try available_tids.ensureTotalCapacityPrecise(arena, n - 1); | 76 | try available_tids.ensureTotalCapacityPrecise(arena, n - 1); |
| 77 | for (1..n) |tid| available_tids.appendAssumeCapacity(@enumFromInt(tid)); | 77 | for (1..n) |tid| available_tids.appendAssumeCapacity(@enumFromInt(tid)); |
| | 78 | switch (build_options.io_mode) { |
| | 79 | .threaded => { |
| | 80 | // Called from the main thread, so mark ourselves as such. |
| | 81 | recursive_depth = 1; |
| | 82 | recursive_tid = .main; |
| | 83 | }, |
| | 84 | .evented => {}, |
| | 85 | } |
| 78 | } | 86 | } |
| 79 | pub fn acquire(io: std.Io) Id { | 87 | pub fn acquire(io: std.Io) Id { |
| 80 | switch (build_options.io_mode) { | 88 | switch (build_options.io_mode) { |
| 81 | .threaded => { | 89 | .threaded => { |
| 82 | recursive_depth += 1; | 90 | recursive_depth += 1; |
| 83 | if (recursive_depth > 1) { | 91 | if (recursive_depth > 1) { |
| 84 | assert(recursive_tid != .main); | | |
| 85 | return recursive_tid; | 92 | return recursive_tid; |
| 86 | } | 93 | } |
| 87 | }, | 94 | }, |
| ... | @@ -106,7 +113,6 @@ pub const Id = if (InternPool.single_threaded) enum { | ... | @@ -106,7 +113,6 @@ pub const Id = if (InternPool.single_threaded) enum { |
| 106 | assert(recursive_tid == tid); | 113 | assert(recursive_tid == tid); |
| 107 | recursive_depth -= 1; | 114 | recursive_depth -= 1; |
| 108 | if (recursive_depth > 0) return; | 115 | if (recursive_depth > 0) return; |
| 109 | recursive_tid = .main; | | |
| 110 | }, | 116 | }, |
| 111 | .evented => {}, | 117 | .evented => {}, |
| 112 | } | 118 | } |