Ejemplo n.º 1
0
int Child(void *arg) {
	printf("In child\n");
	USLOSS_WaitInt();
	USLOSS_WaitInt();
	USLOSS_WaitInt();
	USLOSS_WaitInt();
	USLOSS_WaitInt();
	USLOSS_WaitInt();
	USLOSS_WaitInt();
	USLOSS_WaitInt();
	printf("After wait\n");
	return 0;
}
Ejemplo n.º 2
0
int P1_WaitDevice(int type, int unit, int *status){
  if(procTable[currPid].state==2){//Checks if killed
    return -3;
  }
  /*TO DO: Check If valid Unit*/
  if(unit<0||unit>3){
    return -1;
  }
  Semaphore* sema;
  switch(type){
    case USLOSS_CLOCK_INT:
      if(unit!=1){
        return -1;
      }
      USLOSS_WaitInt();
      *status=-1;
      break;
    case USLOSS_ALARM_INT:
      if(unit!=1){
        return -1;
      }
      sema=&semTable[Alarm_Sema];
      P1_P(sema);
      *status=-1;
      break;
    case USLOSS_DISK_INT:
      if(unit<1||unit>2){
        return -1;
      }
      sema=&semTable[Disk_Sema];
      P1_P(sema);
      *status=-1;
      break;
    case USLOSS_TERM_INT:
      if(unit<1||unit>4){
        return -1;
      }
      sema=&semTable[Term_Sema];
      P1_P(sema);
      *status=-1;
      break;
    default:
      return -2;//Invalid Type
  }
  return 0;
}
Ejemplo n.º 3
0
void
startup()
{
    int	status;
    int i, j, k;
    FILE    *f;
    char    name[50];
    int     n;

    // Compute the inputs and write them to the term*.in file. Each terminal reads unique content.
    k = 0;
    for(i = 0; i < USLOSS_TERM_UNITS; i++) {
        memset(buffers[i], '\0', NUMCHARS);
        counts[i] = 0;
        snprintf(name, sizeof(name), "term%d.in", i);
        f = fopen(name, "w");
        assert(f != NULL);
        for (j = 0; j < NUMCHARS; j++) {
            inputs[i][j] = 'a' + k++;
        }
        n = fwrite(inputs[i], 1, NUMCHARS, f);
        assert(n == NUMCHARS);
        fclose(f);
    }

    for (i = 0; i < USLOSS_NUM_INTS; i++) {
	   USLOSS_IntVec[i] = dummy_handler;
    }
    // Turn on receive interrupts.

    for(i = 0; i < USLOSS_TERM_UNITS; i++) {
        status = USLOSS_DeviceOutput(USLOSS_TERM_DEV, i, (void *) USLOSS_TERM_CTRL_RECV_INT(0));
    }
    USLOSS_IntVec[USLOSS_TERM_INT] = term_handler;

    // Turn on interrupts.
    USLOSS_PsrSet(USLOSS_PsrGet() | USLOSS_PSR_CURRENT_INT);

    // Read from the terminals.
    while(done < USLOSS_TERM_UNITS ) {
	   USLOSS_WaitInt();
    }
    USLOSS_Halt(0);
}
Ejemplo n.º 4
0
void
startup()
{
    int	status;
    int i;

    for (i = 0; i < USLOSS_NUM_INTS; i++) {
	USLOSS_IntVec[i] = dummy_handler;
    }
    // Turn on receive interrupts for terminal 0.
    status = USLOSS_DeviceOutput(USLOSS_TERM_DEV, 0, (void *) USLOSS_TERM_CTRL_RECV_INT(0));
    USLOSS_IntVec[USLOSS_TERM_INT] = term_handler;
    // Turn on interrupts.
    USLOSS_PsrSet(USLOSS_PsrGet() | USLOSS_PSR_CURRENT_INT);
    // Wait in an infinite loops for interrupts.
    while(1) {
	USLOSS_WaitInt();
    }
}
Ejemplo n.º 5
0
/* ------------------------------------------------------------------------
   Name - sentinel
   Purpose - The purpose of the sentinel routine is two-fold.  One
             responsibility is to keep the system going when all other
             processes are blocked.  The other is to detect and report
             simple deadlock states.
   Parameters - none
   Returns - nothing
   Side Effects -  if system is in deadlock, print appropriate error
                   and halt.
   ----------------------------------------------------------------------- */
int sentinel (void *notused)
{
  /*No Interupts within Part 1 so commented out*/
  // int deadlock=1;
  int i;
  // printList(&readyHead);
  while (numProcs > 1){
    USLOSS_Console("in sentinel\n");
    //Check for deadlock here 
    for(i=1;i<P1_MAXPROC;i++){
      if(procTable[i].state == 4&&procTable[i].waitingOnDevice==0){
        USLOSS_Console("Error: Deadlock\n");
        USLOSS_Halt(1);
      }
    }
    USLOSS_WaitInt();
  }
  USLOSS_Halt(0);
  /* Never gets here. */
  return 0;
} /* End of sentinel */