Skip to content

Commit 74e4e59

Browse files
create_thread(): Duplicate sched_data so
Duplicate sched_data for each thread to allow modifying it to keep track of the current state.
1 parent 395e737 commit 74e4e59

File tree

1 file changed

+14
-1
lines changed

1 file changed

+14
-1
lines changed

src/rt-app.c

Lines changed: 14 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -152,6 +152,7 @@ static int thread_data_create_unique_resources(thread_data_t *tdata, const threa
152152
static int create_thread(const thread_data_t *td, int index, int forked, int nforks)
153153
{
154154
thread_data_t *tdata;
155+
sched_data_t *tsched_data;
155156

156157
if (!td) {
157158
log_error("Failed to create new thread, passed NULL thread_data_t: %s", td->name);
@@ -164,14 +165,25 @@ static int create_thread(const thread_data_t *td, int index, int forked, int nfo
164165
return -1;
165166
}
166167

168+
tsched_data = malloc(sizeof(sched_data_t));
169+
if (!tsched_data) {
170+
log_error("Failed to duplicate thread sched data: %s", td->name);
171+
return -1;
172+
}
173+
167174
/*
168175
* We have one tdata created at config parse, but we
169176
* might spawn multiple threads if we were running in
170177
* a loop, so ensure we duplicate the tdata before
171178
* creating each thread, and we should free it at the
172-
* end of the thread_body()
179+
* end of the thread_body().
180+
*
181+
* Also duplicate the sched_data since it is modified by each thread to
182+
* keep track of current sched state.
173183
*/
174184
memcpy(tdata, td, sizeof(*tdata));
185+
tdata->sched_data = tsched_data;
186+
memcpy(tdata->sched_data, td->sched_data, sizeof(*tdata->sched_data));
175187

176188
/* Mark this thread as forked */
177189
tdata->forked = forked;
@@ -733,6 +745,7 @@ static void __shutdown(bool force_terminate)
733745
{
734746
/* clean up tdata if this was a forked thread */
735747
free(threads[i].data->name);
748+
free(threads[i].data->sched_data);
736749
free(threads[i].data);
737750
}
738751

0 commit comments

Comments
 (0)