Example #1
0
void addToBlocked(int pid){

	pNode * p = kmalloc(sizeof(pNode));
	p->process->pid = pid;

	if(isBlockedListNull){
		addProcessToBloqued(p);
		return;
	}
	blockProcess(pid);

}
Example #2
0
bool semaforo_wait(t_semaforo* semaforo,
		t_nodo_proceso_ejecutando* procesoEjecutando)
{
	if (semaforo->valor > 0)
	{
		debugTrackPCP("Wait successful.");
		semaforo->valor--;
		return false;
	}
	debugTrackPCP("Wait could not be satisfied, blocking process.");
	blockProcess(semaforo->bloqueados, procesoEjecutando);
	return true;
}
Example #3
0
//
// Main Function Implementation ///////////////////////////////////
//
   int main( int argc, char* argv[] )
      {
       struct pcb_table myPCB = { 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0 };   // pcb table
       struct pcb_table *pcbPtr = NULL;   //pcb pointer
       bool isThread = false;   // check if the meta a thread
       bool toFile = false;   // check if the log needs to output to file
       int currentProcess = 0;   // current running process
       pthread_t myThread;   // thread

       currentLog = logList;

       // read config file
       readConfig( argv[1], &myPCB );

       // check if need to print to monitor or file
       if(myPCB.logMode == 1 || myPCB.logMode == 2 )
          toMonitor = true;
       if(myPCB.logMode == 1 || myPCB.logMode == 3 )
          toFile = true;

       // read meta data file, update pointer
       readMeta( myPCB.dataFile, &pcbList, myPCB, &processCounter);
       pcbPtr = pcbList;

       // start timer
       clock_gettime( CLOCK_REALTIME, &startTime ); 

       // print start log
       clock_gettime( CLOCK_REALTIME, &endTime );
       totalTime = timeLap( startTime, endTime );
       recordLog( &logList, &currentLog, totalTime, "Simulator program starting" );
       if( toMonitor )
          printLog( currentLog );

       // print log
       clock_gettime( CLOCK_REALTIME, &endTime );
       totalTime = timeLap( startTime, endTime );
       recordLog( &logList, &currentLog, totalTime, "OS: preparing all processes" );
       if( toMonitor )
          printLog( currentLog );

       // loop around processes
       while( processCounter > 0 )
          {
          // if the process hasn't finished
          if( pcbPtr -> current != NULL )
             {
              // print log
              clock_gettime( CLOCK_REALTIME, &endTime );
              totalTime = timeLap( startTime, endTime );
              recordLog( &logList, &currentLog, totalTime, "OS: seleting next process" );
              if( toMonitor )
                 printLog( currentLog );

              // print log
              clock_gettime( CLOCK_REALTIME, &endTime );
              totalTime = timeLap( startTime, endTime );
              metaStartLog( pcbPtr -> current, pcbPtr, logComment );
              recordLog( &logList, &currentLog, totalTime, logComment );
              if( toMonitor )
                 printLog( currentLog );

              // if the current meta is process
              if( pcbPtr -> current -> component == 'P' )
                 {
                  runProcess( pcbPtr -> current, &pcbPtr );
                  if( pcbPtr -> currentLeft == 0 )
                     {
                      clock_gettime( CLOCK_REALTIME, &endTime );
                      totalTime = timeLap( startTime, endTime );
                      interruptLog(pcbPtr -> current, logComment);
                      recordLog( &logList, &currentLog, totalTime, logComment );
                      if( toMonitor )
                         printLog( currentLog );

                      pcbPtr -> current = pcbPtr -> current -> next;
                      if( pcbPtr -> current != NULL && pcbPtr -> current -> component == 'P' )
                         pcbPtr -> currentLeft = pcbPtr -> current -> cyc_time;
                      if(pcbPtr -> current == NULL)
                         processCounter --;
                     }
                 }

              // if the current meta needs spawn thread
              else
                 {
                  // spawn thread
                  pthread_create( &myThread, NULL, thread_perform, (void*) pcbPtr );

                  // print log
                  clock_gettime( CLOCK_REALTIME, &endTime );
                  totalTime = timeLap( startTime, endTime );
                  blockLog(pcbPtr->current, logComment);
                  recordLog( &logList, &currentLog, totalTime, logComment );
                  if( toMonitor )
                     printLog( currentLog );

                  // block process
                  blockProcess(&pcbList, pcbPtr, &blockQueue);
                 }
             }

          // select next process in queue
          if(pcbPtr -> next == NULL)
             pcbPtr = pcbList;
          else
             pcbPtr = pcbPtr -> next;
          }

       // print ending log
       clock_gettime( CLOCK_REALTIME, &endTime );
       totalTime = timeLap( startTime, endTime );
       recordLog( &logList, &currentLog, totalTime, "Simulator program ending" );
       if( toMonitor )
          printLog( currentLog );

       // output to file
       if( toFile )
          outputToFile( logList, myPCB );

       return 0;
      }   // end of main