|
@@ -92,7 +92,7 @@ static inline bool_t is_thread_ready(thread_t *thread)
|
|
|
{
|
|
|
qword_t current_time = syscall_get_milliseconds();
|
|
|
|
|
|
- if (thread->terminating || thread->terminated) return FALSE;
|
|
|
+ if (thread->terminated) return FALSE;
|
|
|
if (thread->frozen > 0 && !thread->in_kernel) return FALSE;
|
|
|
if (!thread->wait) return TRUE;
|
|
|
|
|
@@ -110,6 +110,13 @@ static inline bool_t is_thread_ready(thread_t *thread)
|
|
|
return TRUE;
|
|
|
}
|
|
|
|
|
|
+ if (thread->terminating)
|
|
|
+ {
|
|
|
+ thread->wait->result = WAIT_CANCELED;
|
|
|
+ thread->wait = NULL;
|
|
|
+ return TRUE;
|
|
|
+ }
|
|
|
+
|
|
|
return FALSE;
|
|
|
}
|
|
|
|
|
@@ -178,7 +185,6 @@ dword_t create_thread_internal(process_t *proc, thread_state_t *initial_state, d
|
|
|
thread->exit_code = 0;
|
|
|
thread->terminating = FALSE;
|
|
|
thread->terminated = FALSE;
|
|
|
- thread->in_kernel = 0;
|
|
|
thread->last_context = NULL;
|
|
|
thread->wait = NULL;
|
|
|
memset(&thread->kernel_handler, 0, sizeof(thread->kernel_handler));
|
|
@@ -190,7 +196,7 @@ dword_t create_thread_internal(process_t *proc, thread_state_t *initial_state, d
|
|
|
if (proc != kernel_process)
|
|
|
{
|
|
|
thread->previous_mode = USER_MODE;
|
|
|
-
|
|
|
+ thread->in_kernel = 0;
|
|
|
thread->state.regs.cs = get_user_code_selector();
|
|
|
thread->state.regs.data_selector = get_user_data_selector();
|
|
|
}
|
|
@@ -327,6 +333,7 @@ found:
|
|
|
bump_address_space(¤t_thread->owner_process->memory_space);
|
|
|
}
|
|
|
|
|
|
+ if (current_thread->terminating && !current_thread->in_kernel) current_thread->terminated = TRUE;
|
|
|
if (current_thread->terminated) destroy_thread(current_thread);
|
|
|
current_thread = next_thread;
|
|
|
current_thread->quantum = QUANTUM;
|
|
@@ -496,25 +503,8 @@ found:
|
|
|
|
|
|
dword_t terminate_thread_internal(thread_t *thread, dword_t exit_code)
|
|
|
{
|
|
|
- critical_t critical;
|
|
|
- thread->terminating = TRUE;
|
|
|
-
|
|
|
- if (thread != current_thread)
|
|
|
- {
|
|
|
- wait_condition_t cond = { .type = WAIT_UNTIL_EQUAL, .pointer = (dword_t*)&thread->in_kernel, .value = 0 };
|
|
|
- wait_result_t result = scheduler_wait(&cond, NO_TIMEOUT);
|
|
|
- if (result == WAIT_CANCELED) return ERR_CANCELED;
|
|
|
- }
|
|
|
-
|
|
|
- enter_critical(&critical);
|
|
|
-
|
|
|
thread->exit_code = exit_code;
|
|
|
- thread->terminated = TRUE;
|
|
|
- if (thread != current_thread) destroy_thread(thread);
|
|
|
-
|
|
|
- leave_critical(&critical);
|
|
|
-
|
|
|
- if (thread == current_thread) syscall_yield_quantum();
|
|
|
+ thread->terminating = TRUE;
|
|
|
return ERR_SUCCESS;
|
|
|
}
|
|
|
|