コード例 #1
0
/*******************************************************************
 void runSimulationA(Simulation sim, int iTimeLimit)
 Purpose:
     Runs a simulation on the event list. Prints a table displaying
     the arrival and departures of travelers
 Parameters:
     I   Simulation simulation
     I   int iTimeLimit
 Returns:
     1. Does not return anything functionally
 Notes:
     1. Uses removeLL function
 *******************************************************************/
void runSimulationA(Simulation sim, int iTimeLimit)
{
    Event event;                            // Creates a local event variable to store current
                                            // nodes event information into (uses in simulation evaluation)
    Server server1 = newServer("Server 1");           // Creates a new server -
                                            //  - contains Server Name, whether it is busy or not, and a widget
    Server server2 = newServer("Server 2");            // creates the second server for our program (refer to server1 comments)
    Queue queue1 = newQueue("Queue 1");                // Creates a new queue
    Queue queue2 = newQueue("Queue 2");                // Creates a new queue
    
    if (sim->bVerbose == TRUE)
        printf("%-4s %-6s %-10s\n", "TIME", "WIDGET", "EVENT");      //table header
    
    while (removeLL(sim->eventList, &event))
    {
        // buffer to stop arrivals after the time limit
        if (event.iEventType == EVT_ARRIVAL && event.iTime > iTimeLimit)
            continue;
        
        sim->iClock = event.iTime;  // advance clock to current event time
        
        // the switch evaluates the eventType
        switch(event.iEventType)
        {
            case EVT_ARRIVAL:
                arrival(sim, &event.widget);
                queueUp(sim, queue1, &event.widget);
                seize(sim, queue1, server1);
                break;
            case EVT_SERVER1_COMPLETE:
                release(sim, queue1, server1, &event.widget);
                queueUp(sim, queue2, &event.widget);
                seize(sim, queue2, server2);
                break;
            case EVT_SERVER2_COMPLETE:
                release(sim, queue2, server2, &event.widget);
                leaveSystem(sim, event.widget);
                break;
            default:
                ErrExit(ERR_ALGORITHM, "Unknown event type: %d\n", event.iEventType);
        }
    }
    // prints the averages produced by the simulation
    printStatistics(sim, queue1, queue2);

    // frees servers and queues used in simulation A
    free(server1);
    free(server2);
    free(queue1);
    free(queue2);
}
コード例 #2
0
ファイル: SLList.hpp プロジェクト: 0x00xw/mysql-2
inline
bool
SLListImpl<P, T, U>::seizeN(Ptr<T> & p, Uint32 n)
{
  for(Uint32 i = 0; i < n; i++)
  {
    if(seize(p) == RNIL)
    {
      /**
       * Failure
       */
      for(; i > 0; i--)
      {
	p.i = head.firstItem;
	thePool.getPtr(p);
	head.firstItem = p.p->U::nextList;
	thePool.release(p);
      }
      return false;
    }
  }    

  /**
   * Success
   */
  p.i = head.firstItem;
  p.p = thePool.getPtr(head.firstItem);
  
  return true;
}
コード例 #3
0
ファイル: cs2123p4.c プロジェクト: gopoomemsl/Portfolio
/******************************** release **************************************
void release(Simulation sim, Queue queue, Server server)
Purpose:
	Handles the release event for a given server.
	In this case, just mark the server as not busy and attempt to seize a 
	new widget from the queue.
	This function also prints the event if verbose mode was activated.
Parameters:
	I	Simulation sim		Simulation running the event.
	I	Queue queue			Queue to seize from.
	O	Server server		Server to release the widget from.
Returns:
	server parm - server made available again.
Notes:
*******************************************************************************/
void release(Simulation sim, Queue queue, Server server)
{
	printEvent(sim, " %6d %8ld %s %s", sim->iClock, server->widget.lWidgetNr, 
				"Released", server->szServerName);
	
	//mark the server free
	server->bBusy = FALSE;
	//attempt to seize a new widget for the server
	seize(sim, queue, server);
}
コード例 #4
0
/*************************** release ****************************
 release(Simulation sim, Queue queueTeller, Server serverTeller, Widget *widget)
 Purpose:
     Releases a widget from the server, sets server to no longer busy, and checks
     to see if it can start working on another widget
 Parameters:
     I      Simulation sim              //simulation we are running
     I      Queue queueTeller           //current queue we are dealing with
     I      Server serverTeller         //current server we are working on
     I      Widget *widget              //current widget being released from server
 Returns:
 Notes:
     1. Calls seize
*****************************************************************/
void release(Simulation sim, Queue queueTeller, Server serverTeller, Widget *widget)
{
    // set server to no longer busy
    serverTeller->bBusy = FALSE;

    // update and print stats
    if (sim->bVerbose == TRUE)
        printf("%4d %6ld Released %6s\n", sim->iClock, widget->lWidgetNr, serverTeller->szServerName);
    
    // checks to see if Server could potentially start working on another widget
    seize(sim, queueTeller, serverTeller);
}
コード例 #5
0
ファイル: DataBuffer.hpp プロジェクト: A-eolus/mysql
inline
bool 
DataBuffer<sz>::append(const Uint32* src, Uint32 len){
  if(len == 0)
    return true;
  
  Uint32 pos = head.used;
  if(!seize(len)){
    return false;
  }
  DataBufferIterator it;
  
  if(position(it, pos) && import(it, src, len)){
    return true;
  }
  abort();
  return false;
}
コード例 #6
0
ファイル: WOPool.cpp プロジェクト: A-eolus/mysql
bool
WOPool::seize_new_page(Ptr<void>& ptr)
{
  WOPage* page;
  Uint32 page_no = RNIL;
  if ((page = (WOPage*)m_ctx.alloc_page(m_record_info.m_type_id, &page_no)))
  {
    if (m_current_page)
    {
      m_current_page->m_ref_count = m_current_ref_count;
    }
    
    m_current_pos = 0;
    m_current_ref_count = 0;
    m_current_page_no = page_no;
    m_current_page = page;
    page->m_type_id = m_record_info.m_type_id;
    bool ret = seize(ptr);
    assert(ret);
    return true;
  }
  return false;
}
コード例 #7
0
ファイル: Map.cpp プロジェクト: Qata/Wibbly
bool Map::seize(unsigned tileX, unsigned tileY)
{
	return seize(tileY * width() + tileX);
}
コード例 #8
0
ファイル: cs2123p4.c プロジェクト: gopoomemsl/Portfolio
/**************************** runSimulation ************************************
void runSimulation(Simulation sim, int iTimeLimit)
Purpose:
	Goes through a list of events in a Simulation and run them as they are 
	encountered.
Parameters:
	I	Simulation sim		The simulation variable containing the list of 
							events.
	I	int iTimeLimit		A time limit upon which the simulation will terminate 
							if it is reached before all of the events are ran.
Returns:
Notes:
*******************************************************************************/
void runSimulation(Simulation sim, int iTimeLimit)
{	
	//Variables
	Event event;
	Server server1, server2;
	Queue queue1, queue2;
	
	//create servers and queues
	server1 = newServer("Server 1");
	queue1 = newQueue("Queue 1");
	if (sim->cRunType == 'A')
	{
		server2 = newServer("Server 2");
		queue2 = newQueue("Queue 2");	
	}

	//begin simulation
	printHeader(sim);
	while (removeLL(sim->eventList, &event)) 
	{	
		if (event.iTime > iTimeLimit)
		{
			printFooter(sim, queue1, queue2);	
			freeServersAndQueues(sim, server1, server2, queue1, queue2);	
			ErrExit(ERR_BAD_INPUT, "Event time (%d) is out of simulation bounds (%d)\n", 
					event.iTime, iTimeLimit);
		}

		sim->iClock = event.iTime;
		switch (event.iEventType)
		{
			case EVT_ARRIVAL:
				arrival(sim, &event.widget);
				queueUp(sim, &event.widget, queue1);
				seize(sim, queue1, server1);
				break;

			case EVT_SERVER1_COMPLETE:
				release(sim, queue1, server1);
				if (sim->cRunType == 'A') //Alternative A follows up with server 2
				{
					queueUp(sim, &event.widget, queue2);
					seize(sim, queue2, server2);
				}
				else //Alternative B and Current leave after server 1
				{
					leaveSystem(sim, &event.widget);
				}
				break;

			case EVT_SERVER2_COMPLETE:
				release(sim, queue2, server2);
				leaveSystem(sim, &event.widget);
				break;
		
			default:
				ErrExit(ERR_ALGORITHM, "Unknown event type: %d\n", event.iEventType);
		}
	}
	
	printFooter(sim, queue1, queue2);	
	freeServersAndQueues(sim, server1, server2, queue1, queue2);	
}
コード例 #9
0
 OBJ30_B() { seize(); }