Example #1
0
static char bufferRemove(CircularBuffer* buf)
{
	if (bufferIsEmpty(buf)) return '\0';
	char carattere = buf->content[buf->start];
	buf->start = (buf->start + 1) % BUFFER_LENGTH;
	return carattere;
}
Example #2
0
void writeContentOnBaseChannel(CircularBuffer* buf, BaseChannel* bc)
{
	chMtxLock(&(buf->mutex));
	while (!bufferIsEmpty(buf))
	{
		chprintf(bc, "%c", bufferRemove(buf));
	}
	chMtxUnlock();
}
Example #3
0
static inline uint8_t bufferGet()
{
    uint8_t retVal = 0;

    if (!bufferIsEmpty())
    {
        retVal = sBuffer[sReadPosition++ % RNG_BUFFER_SIZE];
    }

    return retVal;
}
Example #4
0
void WriteThread::internalEndOfFile()
{
    if(!bufferIsEmpty())
    {
        ULTRACOPIER_DEBUGCONSOLE(Ultracopier::DebugLevel_Notice,"["+std::to_string(id)+"] start the write");
        emit internalStartWrite();
    }
    else
    {
        ULTRACOPIER_DEBUGCONSOLE(Ultracopier::DebugLevel_Notice,"["+std::to_string(id)+"] writeIsStopped");
        flushBuffer();
        emit writeIsStopped();
    }
}
Example #5
0
/**bufferGet
 * Get packet pkt from bufferpacket bp.
 * \param pkt : Packet to accept pop
 * \param bp : buffer to pop packet from
 * \return 0 if OK 1 if empty.
 */
uint8_t bufferGet(bufferpacket *bp, char *pkt)
{
	int i;
	char *p;
	char *q;
	if (bufferIsEmpty(bp)) return 1;	// Nothing to get? Return 1
	p=bp->pkt+bp->tail*PACKETSIZE;	// Source
	q=pkt;							// Destination
	// Fetch the packet
	for (i=0;i<PACKETSIZE;i++)
		*q++=*p++;
	// Step the tail pointer	
	bp->tail=(bp->tail+1) % bp->count;
	return 0;
}
Example #6
0
void WriteThread::internalEndOfFile()
{
    if(!bufferIsEmpty())
    {
        if(sequential)
        {
            ULTRACOPIER_DEBUGCONSOLE(Ultracopier::DebugLevel_Notice,QStringLiteral("[")+QString::number(id)+QStringLiteral("] start the write"));
            emit internalStartWrite();
        }
        else
            ULTRACOPIER_DEBUGCONSOLE(Ultracopier::DebugLevel_Notice,QStringLiteral("[")+QString::number(id)+QStringLiteral("] buffer is not empty!"));
    }
    else
    {
        ULTRACOPIER_DEBUGCONSOLE(Ultracopier::DebugLevel_Notice,QStringLiteral("[")+QString::number(id)+QStringLiteral("] writeIsStopped"));
        emit writeIsStopped();
    }
}
Example #7
0
void WriteThread::internalWrite()
{
    const size_t blockSize=sizeof(blockArray);
    int32_t              bytesWriten=0;		///< temp data for block writing, the bytes writen
    uint32_t blockArrayStop=this->blockArrayStop;//load value out of atomic
    uint32_t blockArrayStart=this->blockArrayStart;//load value out of atomic
    bool bytesWasWriten=false;
    if(blockArrayStart==blockArrayStop && !blockArrayIsFull)
    {
        if(!endDetected)
            readThread->callBack();
        return;
    }
    do
    {
        if(stopIt)
        {
            ULTRACOPIER_DEBUGCONSOLE(Ultracopier::DebugLevel_Warning,"["+std::to_string(id)+"] stopIt");
            return;
        }
        if(stopIt)
            return;
        #ifdef ULTRACOPIER_PLUGIN_DEBUG
        status=Write;
        #endif
        errno=0;
        if(blockArrayStop>blockArrayStart)
        {
            void * ptr=blockArray+blockArrayStart;
            const size_t size=blockArrayStop-blockArrayStart;
            bytesWriten=fwrite(ptr,1,size,file);
            if(bytesWriten>0 && (errno==0 || errno==EAGAIN))
                blockArrayStart+=bytesWriten;
        }
        else //if(blockArrayStart==blockSize || blockArrayStop<blockArrayStart)//and then blockArrayIsFull
        {
            void * ptr=blockArray+blockArrayStart;
            const size_t size=blockSize-blockArrayStart;
            bytesWriten=fwrite(ptr,1,size,file);
            if(bytesWriten>0 && (errno==0 || errno==EAGAIN))
                blockArrayStart+=bytesWriten;
        }
        if(blockArrayStart==blockSize)
            blockArrayStart=0;
        #ifdef ULTRACOPIER_PLUGIN_DEBUG
        status=Idle;
        #endif
        if(lastGoodPosition==0)
        {
            ULTRACOPIER_DEBUGCONSOLE(Ultracopier::DebugLevel_Notice,"["+std::to_string(id)+"] emit writeIsStarted()");
            emit writeIsStarted();
        }
        lastGoodPosition+=bytesWriten;
        if(bytesWriten>0)
            bytesWasWriten=true;
        if(stopIt)
            return;
        if(errno!=0 && errno!=EAGAIN)
        {
            ULTRACOPIER_DEBUGCONSOLE(Ultracopier::DebugLevel_Warning,"["+std::to_string(id)+"] Error in writing: "+fileName+", errno: "+std::to_string(errno));
            errorString_internal="Error in writing: "+fileName+" ("+std::string(strerror(errno))+", errno: "+std::to_string(errno)+")";
            stopIt=true;
            emit error();
            return;
        }
    } while(bytesWriten>0 && blockArrayStart!=blockArrayStop);
    if(bytesWasWriten)
        blockArrayIsFull=false;
    //is empty
    if(!endDetected)
        readThread->callBack();
    //improve the performance due to drop block split
    /*if(blockArrayStart==blockArrayStop && !blockArrayIsFull)
    {
        blockArrayStart=BLOCKDEFAULTINITVAL;
        blockArrayStop=BLOCKDEFAULTINITVAL;
    } if manipulate the read thread var, need mutex and lower the performance*/
    this->blockArrayStart=blockArrayStart;
    if(endDetected && bufferIsEmpty())
        internalEndOfFile();
}