static void mputch(int x, int y, int c, unsigned fg, unsigned bg) { Atomic(); mt_cons_gotoxy(x, y); cprintk(fg, bg, "%c", c); Unatomic(); }
bool EnterMonitorTimed(Monitor_t *mon, unsigned msecs) { if ( mon->owner == mt_curr_task ) Panic("EnterMonitorTimed: monitor %s ya ocupado por esta tarea", GetName(mon)); Atomic(); if ( !mon->owner ) { mon->owner = mt_curr_task; Unatomic(); return true; } bool success = WaitQueueTimed(&mon->queue, msecs); Unatomic(); return success; }
static void close_barrier(DIRECTION dir) { Atomic(); while ( get_road(dir, BARRIER_POS) != EMPTY ) Yield(); set_road(dir, BARRIER_POS, BARRIER, BARRIER_FG, ROAD_BG); Unatomic(); set_border(dir, BARRIER_POS-1, NOTHING, BORDER_FG, BORDER_BG); }
void LeaveMonitor(Monitor_t *mon) { if ( mon->owner != mt_curr_task ) Panic("LeaveMonitor: la tarea no posee el monitor %s", GetName(mon)); Atomic(); mon->owner = SignalQueue(&mon->queue); Unatomic(); }
static int mprint(int x, int y, char *format, ...) { int n; va_list args; Atomic(); mt_cons_gotoxy(x, y); mt_cons_setattr(LIGHTCYAN, BLACK); va_start(args, format); n = vprintk(format, args); va_end(args); mt_cons_clreol(); Unatomic(); return n; }
bool WaitConditionTimed(Condition_t *cond, unsigned msecs) { bool success; Monitor_t *mon = cond->monitor; if ( mon->owner != mt_curr_task ) Panic("WaitConditionTimed %s: la tarea no posee el monitor %s", GetName(cond), GetName(cond->monitor)); Atomic(); LeaveMonitor(mon); success = WaitQueueTimed(&cond->queue, msecs); while ( !EnterMonitor(mon) ) // Hay que volver a tomar el monitor si o si ; Unatomic(); return success; }
static void car(void *arg) { DIRECTION *dir = arg; int pos; int carsymbol = *dir == LEFTBOUND ? LEFTCAR : RIGHTCAR; MESSAGE car_in = *dir == LEFTBOUND ? LEFTBOUND_IN : RIGHTBOUND_IN; MESSAGE car_barrier = *dir == LEFTBOUND ? LEFTBOUND_BARRIER : RIGHTBOUND_BARRIER; MESSAGE car_out = *dir == LEFTBOUND ? LEFTBOUND_OUT : RIGHTBOUND_OUT; ++ncars; // suponemos que es atómico for ( pos = 0 ; pos < ROAD_LEN ; pos++ ) { Atomic(); while ( get_road(*dir, pos) != EMPTY ) Yield(); if ( pos < ROAD_END && get_road(*dir, pos+1) != EMPTY ) Delay(TDELAY); while ( get_road(*dir, pos) != EMPTY ) Yield(); set_road(*dir, pos, carsymbol, CAR_FG, CAR_BG); if ( pos == SENSOR1_POS ) Send(ctl, &car_in, sizeof car_in); else if ( pos == BARRIER_POS ) Send(ctl, &car_barrier, sizeof car_barrier); else if ( pos == SENSOR2_POS ) Send(ctl, &car_out, sizeof car_out); if ( pos ) set_road(*dir, pos-1, EMPTY, ROAD_FG, ROAD_BG); Unatomic(); Delay(TDELAY); } set_road(*dir, ROAD_END, EMPTY, ROAD_FG, ROAD_BG); --ncars; }