/** * 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; }
/** * 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; }
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; } }
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; }
/************************************************************************************ * * 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; }
/************************************************************************************ * * 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); }
void SVGGlyphToPathTranslator::moveToNextValidGlyph() { if (m_glyph && !m_svgGlyph.pathData.isEmpty()) return; incrementIndex(); }
GridMapIterator& GridMapIterator::operator ++() { isPassedEnd_ = !incrementIndex(index_, bufferSize_, startIndex_); return *this; }
static int nextIndex(int index) { return incrementIndex(index, 1); }