Skip to content

Commit 72731b6

Browse files
committed
avoid use of thread-local storage
on windows, thread-local storage requires a run-time library. store the shared molecule struct in the board instead. old: 324.91s user 3.07s system 97% cpu 5:34.96 total new: 323.40s user 2.70s system 98% cpu 5:31.06 total see #21
1 parent bca373a commit 72731b6

File tree

2 files changed

+8
-7
lines changed

2 files changed

+8
-7
lines changed

sim.c

Lines changed: 5 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -388,15 +388,13 @@ static void add_atom_to_molecule(struct board *board, struct molecule *molecule,
388388
// TODO: use this for conduits too.
389389
static struct molecule *get_molecule(struct board *board, struct atom_ref_at_position a)
390390
{
391-
static _Thread_local struct molecule molecule;
392-
393-
molecule.size = 0;
391+
board->molecule.size = 0;
394392
// VISITED goes on the bottommost atom of the hex even if it isn't part of the molecule
395393
*lookup_atom(board, a.position) |= VISITED;
396-
add_atom_to_molecule(board, &molecule, a);
397-
for (uint32_t i = 0; i < molecule.size; ++i)
398-
*lookup_atom(board, molecule.atoms[i].position) &= ~VISITED;
399-
return &molecule;
394+
add_atom_to_molecule(board, &board->molecule, a);
395+
for (uint32_t i = 0; i < board->molecule.size; ++i)
396+
*lookup_atom(board, board->molecule.atoms[i].position) &= ~VISITED;
397+
return &board->molecule;
400398
}
401399

402400
static void remove_molecule(struct board *board, struct molecule *molecule)

sim.h

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -461,6 +461,9 @@ struct board {
461461
uint32_t number_of_atoms_being_produced;
462462
uint32_t atoms_being_produced_capacity;
463463

464+
// to reuse allocations, each board has a single, shared molecule struct.
465+
struct molecule molecule;
466+
464467
bool collision;
465468
struct vector collision_location;
466469
const char *collision_reason;

0 commit comments

Comments
 (0)