/* * Start a user-mode thread (i.e., a process), using given user context. * Returns pointer to the new thread if successful, null otherwise. */ struct Kernel_Thread* Start_User_Thread(struct User_Context* userContext, bool detached) { /* * Hints: * - Use Create_Thread() to create a new "raw" thread object * - Call Setup_User_Thread() to get the thread ready to * execute in user mode * - Call Make_Runnable_Atomic() to schedule the process * for execution */ struct Kernel_Thread* kthread; kthread = Create_Thread(PRIORITY_USER, detached); if (kthread != 0) { /* * Create the initial context for the thread to make * it schedulable. */ Setup_User_Thread(kthread, userContext); /* Atomically put the thread on the run queue. */ Make_Runnable_Atomic(kthread); } return kthread; }
/* * Start a user-mode thread (i.e., a process), using given user context. * Returns pointer to the new thread if successful, null otherwise. */ struct Kernel_Thread* Start_User_Thread(struct User_Context* userContext, bool detached) { //lacki /* * Hints: * - Use Create_Thread() to create a new "raw" thread object * - Call Setup_User_Thread() to get the thread ready to * execute in user mode * - Call Make_Runnable_Atomic() to schedule the process * for execution */ //TODO("Start user thread"); struct Kernel_Thread *pKernel_Thread = Create_Thread(PRIORITY_NORMAL, detached); if (pKernel_Thread != 0) { Setup_User_Thread(pKernel_Thread, userContext); Make_Runnable_Atomic(pKernel_Thread); return pKernel_Thread; } else { DEBUG("ERROR: Start_User_Thread - not able to create thread"); return 0; } }
/* * Start a kernel-mode-only thread, using given function as its body * and passing given argument as its parameter. Returns pointer * to the new thread if successful, null otherwise. * * startFunc - is the function to be called by the new thread * arg - is a paramter to pass to the new function * priority - the priority of this thread (use PRIORITY_NORMAL) for * most things * detached - use false for kernel threads */ struct Kernel_Thread* Start_Kernel_Thread( Thread_Start_Func startFunc, ulong_t arg, int priority, bool detached ) { struct Kernel_Thread* kthread = Create_Thread(priority, detached); if (kthread != 0) { /* * Create the initial context for the thread to make * it schedulable. */ Setup_Kernel_Thread(kthread, startFunc, arg); /* Atomically put the thread on the run queue. */ Make_Runnable_Atomic(kthread); } return kthread; }