From: Ben Pfaff Date: Wed, 29 Sep 2004 01:04:16 +0000 (+0000) Subject: Reorder functions. X-Git-Url: https://pintos-os.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=46dd95686f3d7b3dd1c8f9ed72b01cd32d8172f3;p=pintos-anon Reorder functions. --- diff --git a/src/threads/thread.c b/src/threads/thread.c index b1d25db..b0d5a91 100644 --- a/src/threads/thread.c +++ b/src/threads/thread.c @@ -170,9 +170,25 @@ thread_create (const char *name, int priority, return tid; } -/* Transitions a blocked thread T from its current state to the - ready-to-run state. This is an error if T is not blocked. - (Use thread_yield() to make the running thread ready.) */ +/* Puts the current thread to sleep. It will not be scheduled + again until awoken by thread_unblock(). + + This function must be called with interrupts turned off. It + is usually a better idea to use one of the synchronization + primitives in synch.h. */ +void +thread_block (void) +{ + ASSERT (!intr_context ()); + ASSERT (intr_get_level () == INTR_OFF); + + thread_current ()->status = THREAD_BLOCKED; + schedule (); +} + +/* Transitions a blocked thread T to the ready-to-run state. + This is an error if T is not blocked. (Use thread_yield() to + make the running thread ready.) */ void thread_unblock (struct thread *t) { @@ -255,22 +271,6 @@ thread_yield (void) schedule (); intr_set_level (old_level); } - -/* Puts the current thread to sleep. It will not be scheduled - again until awoken by thread_unblock(). - - This function must be called with interrupts turned off. It - is usually a better idea to use one of the synchronization - primitives in synch.h. */ -void -thread_block (void) -{ - ASSERT (!intr_context ()); - ASSERT (intr_get_level () == INTR_OFF); - - thread_current ()->status = THREAD_BLOCKED; - schedule (); -} /* Idle thread. Executes when no other thread is ready to run. */ static void diff --git a/src/threads/thread.h b/src/threads/thread.h index 55ac232..6fcbfc7 100644 --- a/src/threads/thread.h +++ b/src/threads/thread.h @@ -109,6 +109,7 @@ void thread_print_stats (void); typedef void thread_func (void *aux); tid_t thread_create (const char *name, int priority, thread_func *, void *); +void thread_block (void); void thread_unblock (struct thread *); struct thread *thread_current (void); @@ -117,7 +118,6 @@ const char *thread_name (void); void thread_exit (void) NO_RETURN; void thread_yield (void); -void thread_block (void); /* This function will be implemented in problem 1-2. */ void thread_join (tid_t);