Example #1
0
/**
 * @brief RBAllocBuff
 *
 * Allocate memory for buff in rb
 *
 * @param rb pointer to the RB object
 *
 */
void RBAllocBuff(PmLogRingBuffer_t *rb)
{
	/* Lazy allocation for buffer, only when actual write happens */
	if (!rb->buff)
	{
		rb->buff = (char *) g_malloc(rb->bufferSize);
		RBClear(rb);
	}
}
Example #2
0
/**
 * @brief RBFlush
 *
 * Flush
 *
 * @param rb The ring buffer to flush
 * @param flushMsgFunc
 * @param data
 *
 * @return true if we flushed
 */
bool RBFlush(PmLogRingBuffer_t *rb, RBTraversalFunc flushMsgFunc,
             gpointer data)
{
	DbgPrint("%s flush called on rb with bs %d and fl %d\n", __FUNCTION__,
	         rb->bufferSize, rb->flushLevel);

	if (!rb->buff)
	{
		RBAllocBuff(rb);
	}

	g_assert(RBValid(rb));

	/* have RB, need to flush */
	char msg[rb->bufferSize];
	int j = 0;
	int i = 0;
	char *n = rb->nextWritePos;
	int buffSize = rb->bufferSize;

	for (i = 0; i < buffSize; i++)
	{
		msg[j] = *n;
		n = RBStep(rb, n);

		if (msg[j] == '\0')
		{
			if (j != 0)
			{
				flushMsgFunc(msg, data);
			}

			j = 0;
		}
		else
		{
			j++;
		}

		if (n == rb->nextWritePos)
		{
			break;
		}
	}

	RBClear(rb);
	return true;
}
Example #3
0
void DestroyRBTree(struct RBTree* _Tree) {
	RBClear(_Tree);
	free(_Tree);
}