Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- tid_t thread_create(const char *name, int priority,
- thread_func *function, void *aux)
- {
- struct thread *t;
- struct kernel_thread_frame *kf;
- struct switch_entry_frame *ef;
- struct switch_threads_frame *sf;
- tid_t tid;
- ASSERT(function != NULL);
- /* Allocate thread. */
- t = palloc_get_page(PAL_ZERO);
- if (t == NULL)
- return TID_ERROR;
- /* Initialize thread. */
- init_thread(t, name, priority);
- tid = t->tid = allocate_tid();
- t->parent = thread_current();
- enum intr_level old_level = intr_disable();
- child_str *cs = palloc_get_page(0);
- cs->wait_stat = 0;
- cs->t = t;
- cs->tid = tid;
- cs->waited = 0;
- list_push_back(&thread_current()->child_list, &cs->child_elem);
- intr_set_level(old_level);
- t->cwd = NULL;
- if (thread_current()->cwd)
- t->cwd = dir_reopen(thread_current()->cwd);
- /* Stack frame for kernel_thread(). */
- kf = alloc_frame(t, sizeof *kf);
- kf->eip = NULL;
- kf->function = function;
- kf->aux = aux;
- /* Stack frame for switch_entry(). */
- ef = alloc_frame(t, sizeof *ef);
- ef->eip = (void (*)(void))kernel_thread;
- /* Stack frame for switch_threads(). */
- sf = alloc_frame(t, sizeof *sf);
- sf->eip = switch_entry;
- sf->ebp = 0;
- /* Add to run queue. */
- thread_unblock(t);
- return tid;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement