Commit 3318bde5 authored by Naman Dixit's avatar Naman Dixit

Added a thread manager to grunt for dumping instrumentatio data

parent 5a17b288
......@@ -5,7 +5,8 @@
typedef struct Thread {
pthread_t thread;
Char *id;
Char *entity_id;
Char *resource_id;
} Thread;
typedef struct Thread_Tracker {
......@@ -33,7 +34,7 @@ void threadTrackBegin (Thread_Tracker *t, Thread th)
insertion_index = sbufElemin(t->threads) - 1;
}
htInsert(&t->map, hashString(th.id), insertion_index);
htInsert(&t->map, hashString(th.resource_id), insertion_index);
}
internal_function
......@@ -41,7 +42,8 @@ void threadTrackEnd (Thread_Tracker *t, Char *thread_id)
{
Size index = htLookup(&t->map, hashString(thread_id));
sbufAdd(t->free_list, index);
free(t->threads[index].id);
free(t->threads[index].resource_id);
free(t->threads[index].entity_id);
t->threads[index] = (Thread){0};
htRemove(&t->map, index);
}
......@@ -61,16 +63,18 @@ void* tmProcessLoop (void *arg)
switch (command.kind) {
case Thread_Manager_Command_DOCKER_CREATE: {
pthread_t thread;
pthread_create(&thread, NULL, &dockerProcessLoop, NULL);
threadTrackBegin(&tt, (Thread){.id = command.id, .thread = thread});
pthread_create(&thread, NULL, &dockerProcessLoop, command.entity_id);
threadTrackBegin(&tt, (Thread){.entity_id = command.entity_id,
.resource_id = command.resource_id,
.thread = thread});
} break;
case Thread_Manager_Command_DOCKER_DESTROY: {
Size index = htLookup(&tt.map, hashString(command.id));
Size index = htLookup(&tt.map, hashString(command.resource_id));
pthread_t thread = tt.threads[index].thread;
pthread_cancel(thread);
pthread_join(thread, NULL);
threadTrackEnd(&tt, command.id);
threadTrackEnd(&tt, command.resource_id);
} break;
case Thread_Manager_Command_NONE: {
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment