Skip to content
Snippets Groups Projects

Merge patch

Closed Watson, William requested to merge lab2425_autumn/pintos_task0_ww1323:master into master
2 files
+ 25
0
Compare changes
  • Side-by-side
  • Inline
Files
2
+ 18
0
@@ -24,6 +24,9 @@ static int64_t ticks;
Initialized by timer_calibrate(). */
static unsigned loops_per_tick;
struct list sleepers;
struct lock sleepers_lock;
static intr_handler_func timer_interrupt;
static bool too_many_loops (unsigned loops);
static void busy_wait (int64_t loops);
@@ -37,6 +40,9 @@ timer_init (void)
{
pit_configure_channel (0, 2, TIMER_FREQ);
intr_register_ext (0x20, timer_interrupt, "8254 Timer");
list_init(&sleepers);
lock_init(&sleepers_lock);
}
/* Calibrates loops_per_tick, used to implement brief delays. */
@@ -89,8 +95,20 @@ timer_elapsed (int64_t then)
void
timer_sleep (int64_t ticks)
{
if (ticks <= 0) return;
int64_t start = timer_ticks ();
struct list_elem l_elem;
struct semaphore sema;
sema_init(&sema, 0);
struct sleeper my_sleep;
my_sleep.l_elem = l_elem;
my_sleep.t = current_thread();
my_sleep.waking_tick = start + ticks;
my_sleep.sema = &sema;
ASSERT (intr_get_level () == INTR_ON);
while (timer_elapsed (start) < ticks)
thread_yield ();
Loading