Skip to content

Commit b0727e5

Browse files
committed
Fix finding an empty thread state (CID 352965)
Commit a7dcf86 removed the thread limit, but the code to locate an empty slot was broken in the process. It would effectively allocate a new block of slots for each thread. Signed-off-by: Erik Boasson <[email protected]>
1 parent a1a66ca commit b0727e5

File tree

1 file changed

+11
-11
lines changed

1 file changed

+11
-11
lines changed

src/core/ddsi/src/q_thread.c

Lines changed: 11 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -284,22 +284,22 @@ static struct thread_state *grow_thread_states (void)
284284
return &x->thrst[0];
285285
}
286286

287-
static struct thread_state *init_thread_state (const char *tname, const struct ddsi_domaingv *gv, enum thread_state_kind state)
287+
static struct thread_state *get_available_thread_slot ()
288288
{
289289
struct thread_states_list *cur;
290-
uint32_t i = 0; // clearly, if cur != NULL, i will be initialized, but clang ain't so sure
290+
uint32_t i;
291291
for (cur = ddsrt_atomic_ldvoidp (&thread_states.thread_states_head); cur; cur = cur->next)
292292
for (i = 0; i < THREAD_STATE_BATCH; i++)
293293
if (cur->thrst[i].state == THREAD_STATE_ZERO)
294-
break;
295-
struct thread_state *thrst;
296-
if (cur != NULL)
297-
thrst = &cur->thrst[i];
298-
else
299-
{
300-
if ((thrst = grow_thread_states ()) == NULL)
301-
return NULL;
302-
}
294+
return &cur->thrst[i];
295+
return grow_thread_states ();
296+
}
297+
298+
static struct thread_state *init_thread_state (const char *tname, const struct ddsi_domaingv *gv, enum thread_state_kind state)
299+
{
300+
struct thread_state * const thrst = get_available_thread_slot ();
301+
if (thrst == NULL)
302+
return thrst;
303303

304304
assert (vtime_asleep_p (ddsrt_atomic_ld32 (&thrst->vtime)));
305305
ddsrt_atomic_stvoidp (&thrst->gv, (struct ddsi_domaingv *) gv);

0 commit comments

Comments
 (0)