Static thread names.

This commit is contained in:
Geoffrey Challen 2016-03-05 08:46:00 -05:00
parent ca4b4de58b
commit e19a872c2b
3 changed files with 17 additions and 13 deletions

View File

@ -48,6 +48,7 @@ struct cpu;
/* Size of kernel stacks; must be power of 2 */
#define STACK_SIZE 4096
#define MAX_NAME_LENGTH 64
/* Mask for extracting the stack base address of a kernel stack pointer */
#define STACK_MASK (~(vaddr_t)(STACK_SIZE-1))
@ -70,7 +71,16 @@ struct thread {
* These go up front so they're easy to get to even if the
* debugger is messed up.
*/
char *t_name; /* Name of this thread */
/*
* Name of this thread. Used to be dynamically allocated using kmalloc, but
* this can cause small changes in the amount of available memory due to the
* fact that it was cleaned up in exorcise. This produces more predictable
* behavior at the cost of a small amount of memory overhead and the
* inability to give threads huge names.
*/
char t_name[MAX_NAME_LENGTH];
const char *t_wchan_name; /* Name of wait channel, if sleeping */
threadstate_t t_state; /* State this thread is in */

View File

@ -66,10 +66,7 @@ fakethread_create(const char *name)
}
/* ignore most of the fields, zero everything for tidiness */
bzero(t, sizeof(*t));
t->t_name = kstrdup(name);
if (t->t_name == NULL) {
panic("threadlisttest: Out of memory\n");
}
strcpy(t->t_name, name);
t->t_stack = FAKE_MAGIC;
threadlistnode_init(&t->t_listnode, t);
return t;
@ -84,7 +81,6 @@ fakethread_destroy(struct thread *t)
{
KASSERT(t->t_stack == FAKE_MAGIC);
threadlistnode_cleanup(&t->t_listnode);
kfree(t->t_name);
kfree(t);
}

View File

@ -119,17 +119,16 @@ thread_create(const char *name)
struct thread *thread;
DEBUGASSERT(name != NULL);
if (strlen(name) > MAX_NAME_LENGTH) {
return NULL;
}
thread = kmalloc(sizeof(*thread));
if (thread == NULL) {
return NULL;
}
thread->t_name = kstrdup(name);
if (thread->t_name == NULL) {
kfree(thread);
return NULL;
}
strcpy(thread->t_name, name);
thread->t_wchan_name = "NEW";
thread->t_state = S_READY;
@ -280,7 +279,6 @@ thread_destroy(struct thread *thread)
/* sheer paranoia */
thread->t_wchan_name = "DESTROYED";
kfree(thread->t_name);
kfree(thread);
}