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)
{
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 ();
-}
\f
/* Idle thread. Executes when no other thread is ready to run. */
static 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);
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);