Skip to content

Commit 84d608b

Browse files
committed
move next_index inside emutls_control struct
1 parent c8bf39c commit 84d608b

File tree

1 file changed

+6
-5
lines changed

1 file changed

+6
-5
lines changed

lib/std/special/compiler_rt/emutls.zig

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -24,9 +24,6 @@ comptime {
2424
assert(std.builtin.link_libc);
2525
}
2626

27-
// global counter for keeping track of requested indexes.
28-
var global_index: usize = 1;
29-
3027
/// public entrypoint for generated code using EmulatedTLS
3128
pub fn __emutls_get_address(control: *emutls_control) callconv(.C) *c_void {
3229
return control.getPointer();
@@ -245,6 +242,10 @@ const emutls_control = extern struct {
245242
// global Mutex used to serialize control.index initialization.
246243
var mutex: std.c.pthread_mutex_t = std.c.PTHREAD_MUTEX_INITIALIZER;
247244

245+
// global counter for keeping track of requested indexes.
246+
// access should be done with mutex held.
247+
var next_index: usize = 1;
248+
248249
/// Simple wrapper for global lock.
249250
fn lock() void {
250251
if (std.c.pthread_mutex_lock(&emutls_control.mutex) != 0) {
@@ -282,10 +283,10 @@ const emutls_control = extern struct {
282283
}
283284

284285
// Store a new index atomically (for having coherent index_lockless reading).
285-
@atomicStore(usize, &self.object.index, global_index, .Release);
286+
@atomicStore(usize, &self.object.index, emutls_control.next_index, .Release);
286287

287288
// Increment the next available index
288-
global_index += 1;
289+
emutls_control.next_index += 1;
289290

290291
return self.object.index;
291292
}

0 commit comments

Comments
 (0)