unsigned char CircularBufferWrite(CircularBuffer * pCircularBuffer, unsigned char value) { ISTATE state = __get_interrupt_state(); __disable_interrupt(); unsigned char isFull = CircularBufferIsFull(pCircularBuffer); // Verify that there is free space available to write data. if (!isFull) { // Write value at current write pointer position. *(pCircularBuffer->pWrite) = value; // Manipulate pointers. // Compare the current ptr offset position to the buffer start. if (pCircularBuffer->pWrite < pCircularBuffer->pBufferEnd) { // If the pointer address is less than the buffer start address + size of // the buffer, increment the pointer. pCircularBuffer->pWrite = pCircularBuffer->pWrite + 1; } else { // If the pointer reaches the end, set it back to the beginning. pCircularBuffer->pWrite = pCircularBuffer->pBuffer; } } __set_interrupt_state(state); return isFull; }
int CircularBufferEnque(CircularBuffer* que, KeyType k) { int isFull = CircularBufferIsFull(que); que->keys[que->writePointer] = k; que->writePointer++; que->writePointer %= que->size; return isFull; }
inline int CircularBufferEnque(CircularBuffer* que, KeyType k) { int isFull = CircularBufferIsFull(que); if(!isFull) { que->keys[que->writePointer] = k; que->writePointer++; que->writePointer &= que->mask; } return isFull; }
inline int CircularBufferWrite(CircularBuffer* que, void* k) { int isFull = 0; isFull = CircularBufferIsFull(que); que->keys[que->writePointer] = (unsigned int *)calloc(188,sizeof(char)); //*que->keys[que->writePointer] = k; memcpy(que->keys[que->writePointer],k,188); que->writePointer++; que->writePointer %= que->size; return isFull; }
inline int CircularBufferPrint(CircularBuffer* que) { int i=0; int isEmpty = CircularBufferIsEmpty(que); int isFull = CircularBufferIsFull(que); printf("\n==Q: w:%d r:%d f:%d e:%d\n", que->writePointer, que->readPointer, isFull, isEmpty); for(i=0; i< que->size; i++) { printf("%d ", que->keys[i]); } printf("\n"); return(isEmpty); }
inline int CircularBufferEnque(CircularBuffer* que, KeyType k) { int isFull = CircularBufferIsFull(que); if(!isFull) { que->keys[que->writePointer] = k; que->writePointer++; #if IS_BUFFER_SIZE_POWER_OF_TWO que->writePointer &= que->mask; #else que->writePointer %= que->size; #endif } return isFull; }