/*! Read a packet from the queue Wait on the _poperCond if empty If aborted returns immediatly \param ptr : Ptr where to put the packet \param size : returns packetsize */ uint8_t PacketQueue::Pop(uint8_t *ptr, uint32_t *size,uint32_t *sample) { uint8_t r=0; uint32_t slot; uint32_t available,sz,position; _mutex->lock(); // is there something ? while(IsEmpty() && !_eof) { _poperCond->wait(); _mutex->lock(); } if(IsEmpty() && _eof) { *size=0; _mutex->unlock(); return 0; } // //printf("Pop : Head %u Tail %u\n",_slotHead,_slotQueue); // ok, which slot ? slot=_slotQueue; _slotQueue++; _slotQueue%=_nbSlots; sz=*size=_slots[slot].size; *sample=_slots[slot].sample; //printf("Poping slot %d at %u\n",slot,_bufferQueue,_slots[slot].startAt); if(!_bufferQueue==_slots[slot].startAt) { printf("Buffer Q:%u\n",_bufferQueue); printf("Slot :%u\n",_slots[slot].startAt); ADM_assert(0); } if(_bufferSize>=(_bufferQueue+sz)) { memcpy(ptr,&(_buffer[_bufferQueue]),sz); _bufferQueue+=sz; _bufferQueue%=_bufferSize; } else // Split { uint32_t part1=_bufferSize-_bufferQueue; memcpy(ptr,&_buffer[ _bufferQueue],part1); memcpy(ptr+part1,&_buffer[ 0],sz-part1); _bufferQueue=sz-part1; } // In case we made some space if(_pusherCond->iswaiting()) { uint32_t third=(2*_bufferSize)/3; uint32_t available=availableSpace(); // Only wakeup if we go over 1/3 of the buffer ADM_assert(available>=sz); if(available > third) _pusherCond->wakeup(); } _mutex->unlock(); return 1; }
/*! Put a packet in the buffer Wait on _pusherCond if no slot available or buffer full \param ptr : Ptr where to take the packet from \param size : packetsize */ uint8_t PacketQueue::Push(uint8_t *ptr, uint32_t size,uint32_t sample) { uint8_t r=0; uint32_t slot; uint32_t available; _mutex->lock(); // First try to allocate a slot while(((_nbSlots+_slotHead-_slotQueue)%_nbSlots)==1) { _pusherCond->wait(); _mutex->lock(); } // Ok we have a slot, // Now lets's see if we have enough data in the buffer (we are still under lock) while(!_eof) { available=availableSpace(); if(available>=size) { slot=_slotHead; _slotHead++; _slotHead%=_nbSlots; _slots[slot].size=size; _slots[slot].sample=sample; _slots[slot].startAt=_bufferHead; // printf("Pushing slot %d at %u\n",slot,_bufferHead,_slots[slot].startAt); if(_bufferSize>=(_bufferHead+size)) { memcpy(&_buffer[ _bufferHead],ptr,size); _bufferHead+=size; } else // Split { uint32_t part1=_bufferSize-_bufferHead; memcpy(&_buffer[ _bufferHead],ptr,part1); memcpy(&_buffer[ 0],ptr+part1,size-part1); _bufferHead=size-part1; } // Look if someone was waiting ... if(_poperCond->iswaiting()) { _poperCond->wakeup(); } _mutex->unlock(); return 1; } _pusherCond->wait(); _mutex->lock(); } _mutex->unlock(); printf("[PKTQ] %s is eof\n",_name); return 0; }
size_t write(const char *buf, size_t len) { size_t b = std::min(availableSpace(), len); size_t index = end; for (size_t i = 0; i < b; i++) { storage[index] = buf[i]; index = (index + 1) % capacity; } end = index; size += b; return b; }
void PreallocBuffer::dumpInfo(){ DLog("PreallocBuffer begin:%p, writer:%p(%zd), reader:%p(%zd)\n", m_preBuffer, m_writePointer, availableSpace(), m_readPointer, availableBytes()); }
/** * Get raw pointer and availble size for write * * @param bufferPtr raw write pointer * @param availableSpacePtr how many bytes can write */ void PreallocBuffer::getWriteBuffer(uint8_t **bufferPtr, size_t *availableSpacePtr){ if (bufferPtr) *bufferPtr = m_writePointer; if (availableSpacePtr) *availableSpacePtr = availableSpace(); }
void nsSVGForeignObjectFrame::DoReflow() { NS_ASSERTION(!(nsSVGUtils::GetOuterSVGFrame(this)-> GetStateBits() & NS_FRAME_FIRST_REFLOW), "Calling InitialUpdate too early - must not call DoReflow!!!"); // Skip reflow if we're zero-sized, unless this is our first reflow. if (IsDisabled() && !(GetStateBits() & NS_FRAME_FIRST_REFLOW)) return; if (GetStateBits() & NS_STATE_SVG_NONDISPLAY_CHILD) return; nsPresContext *presContext = PresContext(); nsIFrame* kid = GetFirstChild(nsnull); if (!kid) return; // initiate a synchronous reflow here and now: nsSize availableSpace(NS_UNCONSTRAINEDSIZE, NS_UNCONSTRAINEDSIZE); nsIPresShell* presShell = presContext->PresShell(); NS_ASSERTION(presShell, "null presShell"); nsRefPtr<nsRenderingContext> renderingContext = presShell->GetReferenceRenderingContext(); if (!renderingContext) return; nsSVGForeignObjectElement *fO = static_cast<nsSVGForeignObjectElement*> (mContent); float width = fO->mLengthAttributes[nsSVGForeignObjectElement::WIDTH].GetAnimValue(fO); float height = fO->mLengthAttributes[nsSVGForeignObjectElement::HEIGHT].GetAnimValue(fO); // Clamp height & width to be non-negative (to match UpdateCoveredRegion). width = NS_MAX(width, 0.0f); height = NS_MAX(height, 0.0f); nsSize size(nsPresContext::CSSPixelsToAppUnits(width), nsPresContext::CSSPixelsToAppUnits(height)); mInReflow = PR_TRUE; nsHTMLReflowState reflowState(presContext, kid, renderingContext, nsSize(size.width, NS_UNCONSTRAINEDSIZE)); nsHTMLReflowMetrics desiredSize; nsReflowStatus status; // We don't use size.height above because that tells the child to do // page/column breaking at that height. NS_ASSERTION(reflowState.mComputedBorderPadding == nsMargin(0, 0, 0, 0) && reflowState.mComputedMargin == nsMargin(0, 0, 0, 0), "style system should ensure that :-moz-svg-foreign content " "does not get styled"); NS_ASSERTION(reflowState.ComputedWidth() == size.width, "reflow state made child wrong size"); reflowState.SetComputedHeight(size.height); ReflowChild(kid, presContext, desiredSize, reflowState, 0, 0, NS_FRAME_NO_MOVE_FRAME, status); NS_ASSERTION(size.width == desiredSize.width && size.height == desiredSize.height, "unexpected size"); FinishReflowChild(kid, presContext, &reflowState, desiredSize, 0, 0, NS_FRAME_NO_MOVE_FRAME); mInReflow = PR_FALSE; FlushDirtyRegion(0); }
inline Unit availableSpaceDown(const Item& item) { return availableSpace(item, Dir::DOWN); }
inline Unit availableSpaceLeft(const Item& item) { return availableSpace(item, Dir::LEFT); }