Skip to content

Commit 1e73c31

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

File tree

2 files changed

+8
-7
lines changed

2 files changed

+8
-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: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -114,6 +114,8 @@ int fr_thread_setup(fr_thread_t *out, char const *name)
114114
TALLOC_CTX *ctx;
115115
fr_event_list_t *el;
116116

117+
out->name = name;
118+
117119
#ifndef __APPLE__
118120
/*
119121
* OSX doesn't use pthread_signmask in its setcontext
@@ -146,7 +148,6 @@ int fr_thread_setup(fr_thread_t *out, char const *name)
146148
* Do NOT initialize the entire structure. Fields like "id" and "entry" have already been
147149
* initialize and used by the main thread coordinator.
148150
*/
149-
out->name = name;
150151
out->ctx = ctx;
151152
out->el = el;
152153
out->status = FR_THREAD_INITIALIZING;
@@ -217,6 +218,11 @@ void fr_thread_start(fr_thread_t *thread, fr_sem_t *sem)
217218
*/
218219
void fr_thread_exit(fr_thread_t *thread, fr_thread_status_t status, fr_sem_t *sem)
219220
{
221+
/*
222+
* Maybe nothing was initialized, so we don't need to do anything.
223+
*/
224+
if (thread->status == FR_THREAD_FREE) return;
225+
220226
INFO("%s - Exiting", thread->name);
221227

222228
thread->status = status;

0 commit comments

Comments
 (0)