コード例 #1
0
ファイル: portalloc.c プロジェクト: AkankshaGovil/Automation
/**
 * returns the next available port in the range, returns -1 if no ports are available
 * if reqport is not 0 then assigns the requested port
 */
int
allocPort (PortAlloc *ptr, int reqport, dirxn d)
{
	int port = -1;
	int count, index = 0;

	NETDEBUG(MFCE, NETLOG_DEBUG4, ("allocPort: request to allocate port %d for %s\n", reqport, dirxn2str(d)));

	if (!ptr->inited)
	{
		NETERROR(MFCE, ("allocPort: trying to allocate port before initialization\n"));
		return -1;
	}

	if (reqport) {
		index = (reqport - ptr->low)/2;
	}
	else {
		if ((index = nextIndex(ptr)) == -1) {
			NETERROR(MFCE, ("allocPort: cannot allocate port, no more ports available in the range %d - %d\n", ptr->low, ptr->high));
			return -1;	// no ports available in the port range
		}
		
		incrementIndex(ptr);	/* get ready for the next request */

		reqport = (index * 2) + ptr->low;
	}

	/* set the current port as used */
	if (d == rx) {
		if (GET_RX_CNT(ptr->bArray[index])) {
			/* port is already allocated */
			NETERROR(MFCE, ("allocPort: can not allocate rx port on %d.\n", reqport));
			return port;
		}
		SET_RX_CNT(ptr->bArray[index], 1);
	}
	else if (d == tx) {	
		count = GET_TX_CNT(ptr->bArray[index]);
		count++;
		if (count <= MAX_TX_CNT) {
			SET_TX_CNT(ptr->bArray[index], count);
		}
		else {
			NETERROR(MFCE, ("allocPort: can not allocate %d tx ports on %d.\n", count, reqport));
			return port;	// no ports available in the port range
		}
	}
	else {
		NETERROR(MFCE, ("allocPort: can not allocate port for %s(%d).\n", dirxn2str(d), d));
		return port;
	}

	port = reqport;

	NETDEBUG(MFCE, NETLOG_DEBUG4, ("allocPort: allocating port %d for %s\n", port, dirxn2str(d)));
	return port;
}
コード例 #2
0
ファイル: portalloc.c プロジェクト: AkankshaGovil/Automation
/**
 * makes the index pointer point to the next available port bit, returns -1 if all ports
 * in the range have been allocated
 */
static int
nextIndex (PortAlloc *ptr)
{
	int startIndex = ptr->curIndex;

	do
	{
		if (ptr->bArray[ptr->curIndex] == FREEPORT)
			return ptr->curIndex;
		incrementIndex(ptr);
	} while (ptr->curIndex != startIndex);

	return -1;
}
コード例 #3
0
ファイル: unichar_queue.c プロジェクト: tjmiaowang/FTS
void UnicharQueue_consumeChars(UnicharQueue* self, unsigned count)
{
    unsigned len = UnicharQueue_length(self);
    if (count > len)
        count = len;

    if (count > 0)
    {
        self->tail = incrementIndex(self->tail, count);

        if (self->tail == self->head)
            self->tail = -1;
    }
}
コード例 #4
0
Path SVGGlyphToPathTranslator::nextPath()
{
    if (m_isVerticalText) {
        m_glyphOrigin.setX(m_svgGlyph.verticalOriginX * m_scale);
        m_glyphOrigin.setY(m_svgGlyph.verticalOriginY * m_scale);
    }

    AffineTransform glyphPathTransform;
    glyphPathTransform.translate(m_currentPoint.x() + m_glyphOrigin.x(), m_currentPoint.y() + m_glyphOrigin.y());
    glyphPathTransform.scale(m_scale, -m_scale);

    Path glyphPath = m_svgGlyph.pathData;
    glyphPath.transform(glyphPathTransform);
    incrementIndex();
    return glyphPath;
}
コード例 #5
0
ファイル: queue.c プロジェクト: phrocker/TestBase
/************************************************************************************
*
*	getFrontElement
*
*	Removes and returns the element at the front of the queue
*      
*	Arguments:
*
*      Queue inputQueue
*
*	Return Value:
*
*		Pointer to the element at the front of the queue
*
*************************************************************************************/
command *getFrontElement(Queue inputQueue) {

  command *X = NULL;


  if (!isQueueEmpty(inputQueue)) 
  {
      inputQueue->currentSize--;
      X = &inputQueue->localDataStructure[inputQueue->currentFrontIndex];
      
      incrementIndex(&inputQueue->currentFrontIndex,&inputQueue->currentCapacity);
      
      //inputQueue->Front = Succ(inputQueue->Front, inputQueue);
  }

  return X;

}
コード例 #6
0
ファイル: queue.c プロジェクト: phrocker/TestBase
/************************************************************************************
*
*	addElementToQueue
*
*	Adds a new data element to the queue
*      
*	Arguments:
*
*     char *data - localDataStructure of data
*     short size - Size of data array
*     int i     -  ?
*     short type - Type of data
*     uint threadNumber - Thread number to which this queue belongs
*     uint fd - Queue's file descriptor
*     Queue inputQueue - Input queue
*
*	Return Value:
*
*		void
*
*************************************************************************************/
void addElementToQueue(char *data,short size,int i, short type,uint threadNumber,uint fd, Queue inputQueue) {

    if (isQueueFull(inputQueue))
    {
        if (inputQueue->growOnDemand)
        {
          // effectively double the size of the capacity
          increaseQueueCapacity(inputQueue,inputQueue->currentCapacity);
        }
    }

    
    
    
    // increase the current size of our queue
    inputQueue->currentSize++;

    incrementIndex(&inputQueue->currentRearIndex,&inputQueue->currentCapacity);
    //inputQueue->Rear = Succ(inputQueue->currentRearIndex, inputQueue);
    // free data from the previously set packet
    free(inputQueue->localDataStructure[inputQueue->currentRearIndex].data);  
    // free data for the file descriptor in our packet
    free(inputQueue->localDataStructure[inputQueue->currentRearIndex].fd);
    //int i=0;
    // allocate memory for our data
    inputQueue->localDataStructure[inputQueue->currentRearIndex].data = (char*)malloc((size)*sizeof(char));
    // set data to all nulls
    memset(inputQueue->localDataStructure[inputQueue->currentRearIndex].data,0x00,size);
    // allocate memory for our file descriptor
    inputQueue->localDataStructure[inputQueue->currentRearIndex].fd = (int*)malloc(sizeof(int));
    inputQueue->localDataStructure[inputQueue->currentRearIndex].threadNumber=threadNumber;
    inputQueue->localDataStructure[inputQueue->currentRearIndex].connection=i;
    *inputQueue->localDataStructure[inputQueue->currentRearIndex].fd=fd;
    inputQueue->localDataStructure[inputQueue->currentRearIndex].type=type;
    // copy the data into our packet
    strncpy(inputQueue->localDataStructure[inputQueue->currentRearIndex].data,data,size);
    
    
}
コード例 #7
0
void SVGGlyphToPathTranslator::moveToNextValidGlyph()
{
    if (m_glyph && !m_svgGlyph.pathData.isEmpty())
        return;
    incrementIndex();
}
コード例 #8
0
GridMapIterator& GridMapIterator::operator ++()
{
  isPassedEnd_ = !incrementIndex(index_, bufferSize_, startIndex_);
  return *this;
}
コード例 #9
0
ファイル: unichar_queue.c プロジェクト: tjmiaowang/FTS
static int nextIndex(int index)
{
    return incrementIndex(index, 1);
}