Skip to content

Commit 0166f41

Browse files
committed
minor cleanups in thread code
1 parent 3c7754e commit 0166f41

File tree

2 files changed

+7
-7
lines changed

2 files changed

+7
-7
lines changed

src/lib/io/schedule.c

Lines changed: 1 addition & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -121,7 +121,6 @@ static void *fr_schedule_worker_thread(void *arg)
121121
fr_schedule_worker_t *sw = talloc_get_type_abort(arg, fr_schedule_worker_t);
122122
fr_schedule_t *sc = sw->sc;
123123
fr_thread_status_t status = FR_THREAD_FAIL;
124-
fr_schedule_network_t *sn;
125124
char worker_name[32];
126125

127126
worker_id = sw->thread.id; /* Store the current worker ID */
@@ -157,9 +156,7 @@ static void *fr_schedule_worker_thread(void *arg)
157156
/*
158157
* Add this worker to all network threads.
159158
*/
160-
for (sn = fr_dlist_head(&sc->networks);
161-
sn != NULL;
162-
sn = fr_dlist_next(&sc->networks, sn)) {
159+
fr_dlist_foreach(&sc->networks, fr_schedule_network_t, sn) {
163160
if (unlikely(fr_network_worker_add(sn->nr, sw->worker) < 0)) {
164161
PERROR("%s - Failed adding worker to network %u", worker_name, sn->thread.id);
165162
goto fail; /* FIXME - Should maybe try to undo partial adds? */
@@ -217,8 +214,6 @@ static void *fr_schedule_network_thread(void *arg)
217214

218215
if (fr_thread_setup(&sn->thread, network_name) < 0) goto fail;
219216

220-
INFO("%s - Starting", network_name);
221-
222217
sn->nr = fr_network_create(sn->thread.ctx, sn->thread.el, network_name, sc->log, sc->lvl, &sc->config->network);
223218
if (!sn->nr) {
224219
PERROR("%s - Failed creating network", network_name);

src/lib/io/thread.c

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -146,7 +146,7 @@ int fr_thread_setup(fr_thread_t *out, char const *name)
146146
* Do NOT initialize the entire structure. Fields like "id" and "entry" have already been
147147
* initialize and used by the main thread coordinator.
148148
*/
149-
out->name = name;
149+
out->name = talloc_strdup(ctx, name);
150150
out->ctx = ctx;
151151
out->el = el;
152152
out->status = FR_THREAD_INITIALIZING;
@@ -217,6 +217,11 @@ void fr_thread_start(fr_thread_t *thread, fr_sem_t *sem)
217217
*/
218218
void fr_thread_exit(fr_thread_t *thread, fr_thread_status_t status, fr_sem_t *sem)
219219
{
220+
/*
221+
* Maybe nothing was initialized, so we don't need to do anything.
222+
*/
223+
if (thread->status == FR_THREAD_FREE) return;
224+
220225
INFO("%s - Exiting", thread->name);
221226

222227
thread->status = status;

0 commit comments

Comments
 (0)