Skip to content

Commit 85f29b6

Browse files
create_thread(): Duplicate sched_data
Duplicate sched_data for each thread to allow modifying it to keep track of the current thread sched state.
1 parent 9840cd9 commit 85f29b6

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
@@ -158,6 +158,7 @@ static int thread_data_create_unique_resources(thread_data_t *tdata, const threa
158158
static int create_thread(const thread_data_t *td, int index, int forked, int nforks)
159159
{
160160
thread_data_t *tdata;
161+
sched_data_t *tsched_data;
161162

162163
if (!td) {
163164
log_error("Failed to create new thread, passed NULL thread_data_t: %s", td->name);
@@ -170,14 +171,25 @@ static int create_thread(const thread_data_t *td, int index, int forked, int nfo
170171
return -1;
171172
}
172173

174+
tsched_data = malloc(sizeof(sched_data_t));
175+
if (!tsched_data) {
176+
log_error("Failed to duplicate thread sched data: %s", td->name);
177+
return -1;
178+
}
179+
173180
/*
174181
* We have one tdata created at config parse, but we
175182
* might spawn multiple threads if we were running in
176183
* a loop, so ensure we duplicate the tdata before
177184
* creating each thread, and we should free it at the
178-
* end of the thread_body()
185+
* end of the thread_body().
186+
*
187+
* Also duplicate the sched_data since it is modified by each thread to
188+
* keep track of current sched state.
179189
*/
180190
memcpy(tdata, td, sizeof(*tdata));
191+
tdata->sched_data = tsched_data;
192+
memcpy(tdata->sched_data, td->sched_data, sizeof(*tdata->sched_data));
181193

182194
/* Mark this thread as forked */
183195
tdata->forked = forked;
@@ -739,6 +751,7 @@ static void __shutdown(bool force_terminate)
739751
{
740752
/* clean up tdata if this was a forked thread */
741753
free(threads[i].data->name);
754+
free(threads[i].data->sched_data);
742755
if (threads[i].data->def_cpu_data.cpuset)
743756
CPU_FREE(threads[i].data->def_cpu_data.cpuset);
744757

0 commit comments

Comments
 (0)