group/pintos/src/threads/thread.c
/* Does basic initialization of T as a blocked thread named
   NAME. */
Does basic initialization of T as a blocked thread named
NAME.
Does basic initialization of T as a blocked thread named NAME .
static void
init_thread (struct thread *t, const char *name, int priority)
{
  enum intr_level old_level;
  struct thread *cur = NULL;
  if (strcmp(name, "main") != 0)
      cur = thread_current();
  ASSERT (t != NULL);
  ASSERT (PRI_MIN <= priority && priority <= PRI_MAX);
  ASSERT (name != NULL);
  memset (t, 0, sizeof *t);
  t->status = THREAD_BLOCKED;
  strlcpy (t->name, name, sizeof t->name);
  list_init(&t->fds);
  lock_init(&t->fds_lock);
  t->stack = (uint8_t *) t + PGSIZE;
  t->magic = THREAD_MAGIC;
  list_init(&t->holdings);
  t->waiting = NULL;
  t->waiting_sema = NULL;
  list_init(&t->children);
  memset(t->cwd, 0, sizeof(char) * PATH_MAX);
  if (cur == NULL) {
    *(t->cwd) = '/';
    t->recent_cpu = fix_int(0);
    t->nice = 0;
  }
  else {
    memcpy(t->cwd, cur->cwd, strlen(cur->cwd));
    t->recent_cpu = cur->recent_cpu;
    t->nice = cur->nice;
  }
  if (thread_mlfqs)
    t->priority = mlfqs_get_priority(t);
  else
    t->priority = priority;
  old_level = intr_disable ();
  list_push_back (&all_list, &t->allelem);
  intr_set_level (old_level);
}
static void init_thread ( struct thread * t , const char * name , int priority ) { enum intr_level old_level ; struct thread * cur = NULL ; if ( strcmp ( name , " " ) != 0 ) cur = thread_current ( ) ; ASSERT ( t != NULL ) ; ASSERT ( PRI_MIN <= priority && priority <= PRI_MAX ) ; ASSERT ( name != NULL ) ; memset ( t , 0 , sizeof * t ) ; t -> status = THREAD_BLOCKED ; strlcpy ( t -> name , name , sizeof t -> name ) ; list_init ( & t -> fds ) ; lock_init ( & t -> fds_lock ) ; t -> stack = ( uint8_t * ) t + PGSIZE ; t -> magic = THREAD_MAGIC ; list_init ( & t -> holdings ) ; t -> waiting = NULL ; t -> waiting_sema = NULL ; list_init ( & t -> children ) ; memset ( t -> cwd , 0 , sizeof ( char ) * PATH_MAX ) ; if ( cur == NULL ) { * ( t -> cwd ) = ' ' ; t -> recent_cpu = fix_int ( 0 ) ; t -> nice = 0 ; } else { memcpy ( t -> cwd , cur -> cwd , strlen ( cur -> cwd ) ) ; t -> recent_cpu = cur -> recent_cpu ; t -> nice = cur -> nice ; } if ( thread_mlfqs ) t -> priority = mlfqs_get_priority ( t ) ; else t -> priority = priority ; old_level = intr_disable ( ) ; list_push_back ( & all_list , & t -> allelem ) ; intr_set_level ( old_level ) ; }
Does basic initialization of T as a blocked thread named
NAME.
Does basic initialization of T as a blocked thread named NAME .
// current thread is main thread // properties inherit from parent process