Exemple #1
0
/*
 * Create a thread. This is used both to create a first thread
 * for each CPU and to create subsequent forked threads.
 */
static
struct thread *
thread_create(const char *name)
{
    struct thread *thread;
    int i;
    DEBUGASSERT(name != NULL);
    if (strlen(name) > MAX_NAME_LENGTH) {
        return NULL;
    }

    thread = kmalloc(sizeof(*thread));
    if (thread == NULL) {
        return NULL;
    }

    strcpy(thread->t_name, name);
    thread->t_wchan_name = "NEW";
    thread->t_state = S_READY;

    /* Thread subsystem fields */
    thread_machdep_init(&thread->t_machdep);
    threadlistnode_init(&thread->t_listnode, thread);
    thread->t_stack = NULL;
    thread->t_context = NULL;
    thread->t_cpu = NULL;
    thread->t_proc = NULL;

    /* Interrupt state fields */
    thread->t_in_interrupt = false;
    thread->t_curspl = IPL_HIGH;
    thread->t_iplhigh_count = 1; /* corresponding to t_curspl */

    /* If you add to struct thread, be sure to initialize here */
    for(i= 0; i < OPEN_MAX; i++) {
        thread->t_fdtable[i] = NULL;
    }
    return thread;
}
Exemple #2
0
/*
 * Create a thread. This is used both to create a first thread
 * for each CPU and to create subsequent forked threads.
 */
static
struct thread *
thread_create(const char *name)
{
	struct thread *thread;

	DEBUGASSERT(name != NULL);

	thread = kmalloc(sizeof(*thread));
	if (thread == NULL) {
		return NULL;
	}

	thread->t_name = kstrdup(name);
	if (thread->t_name == NULL) {
		kfree(thread);
		return NULL;
	}
	thread->t_wchan_name = "NEW";
	thread->t_state = S_READY;

	/* Thread subsystem fields */
	thread_machdep_init(&thread->t_machdep);
	threadlistnode_init(&thread->t_listnode, thread);
	thread->t_stack = NULL;
	thread->t_context = NULL;
	thread->t_cpu = NULL;
	thread->t_proc = NULL;

	/* Interrupt state fields */
	thread->t_in_interrupt = false;
	thread->t_curspl = IPL_HIGH;
	thread->t_iplhigh_count = 1; /* corresponding to t_curspl */

	/* If you add to struct thread, be sure to initialize here */

	return thread;
}