Beispiel #1
0
err_code resume_thread(thread_id id) {
  err_code err = ERR_NONE;
  CAST_TO_THREAD(thrd, id);

  acquire_spinlock(&inactive.lock);
  if (thrd->state == THREAD_STATE_PAUSED) {
    thrd->state = THREAD_STATE_UNKNOWN;
    if (inactive.tail == thrd)
      inactive.tail = thrd->next;
    if (thrd->next)
      thrd->next->prev = thrd->prev;
    if (thrd->prev)
      thrd->prev->next = thrd->next;
    inactive.total_threads--;
  }
  else
    err = ERR_BAD_STATE;
  release_spinlock(&inactive.lock);

  if (!err) {
    thrd->real_priority = thrd->priority;
    thrd->quantum = 0;
    update_priority_quantum(thrd);

    struct cpu_task task = { .type = CPU_TASK_RESUME, .thread = thrd };
    run_cpu_task(find_least_loaded_cpu(thrd->affinity), &task);
  }
Beispiel #2
0
err_code detach_thread(thread_id id, struct thread_data **thread) {
  err_code err = ERR_NONE;
  CAST_TO_THREAD(thrd, id);

  acquire_spinlock(&all.lock, 0);
  acquire_spinlock(&inactive.lock, 0);

  if (thrd->state == THREAD_STATE_PAUSED ||
      thrd->state == THREAD_STATE_STOPPED) {
    if (thrd->next)
      thrd->next->prev = thrd->prev;
    if (thrd->prev)
      thrd->prev->next = thrd->next;
    if (inactive.tail == thrd)
      inactive.tail = thrd->next;
    inactive.total_threads--;

   if (thrd->all_next)
      thrd->all_next->all_prev = thrd->all_prev;
    if (thrd->all_prev)
      thrd->all_prev->all_next = thrd->all_next;
    if (all.tail == thrd)
      all.tail = thrd->next;
    all.total_threads--;

    thrd->magic = 0;
    thrd->prev = thrd->next = NULL;
    thrd->all_prev = thrd->all_next = NULL;
    *thread = thrd;
  }
  else
    err = ERR_BAD_STATE;

  release_spinlock(&inactive.lock);
  release_spinlock(&all.lock);

  return err;
}