MCPcopy Create free account
hub / github.com/RedisGraph/RedisGraph / CircularBuffer_Read

Function CircularBuffer_Read

src/util/circular_buffer.c:171–202  ·  view source on GitHub ↗

read oldest item from buffer

Source from the content-addressed store, hash-verified

169
170// read oldest item from buffer
171void *CircularBuffer_Read
172(
173 CircularBuffer cb, // buffer to read item from
174 void *item // [optional] pointer populated with removed item
175) {
176 ASSERT(cb != NULL);
177
178 // make sure there's data to return
179 if(unlikely(CircularBuffer_Empty(cb))) {
180 return NULL;
181 }
182
183 void *read = cb->read;
184
185 // update buffer item count
186 cb->item_count--;
187
188 // copy item from buffer to output
189 if(item != NULL) {
190 memcpy(item, cb->read, cb->item_size);
191 }
192
193 // advance read position
194 // circle back if read reached the end of the buffer
195 cb->read += cb->item_size;
196 if(unlikely(cb->read >= cb->end_marker)) {
197 cb->read = cb->data;
198 }
199
200 // return original read position
201 return read;
202}
203
204// free buffer (does not free its elements if its free callback is NULL)
205void CircularBuffer_Free

Callers 7

QueriesLog_FreeFunction · 0.85
_stream_queriesFunction · 0.85
_indexer_PopTaskFunction · 0.85
test_CircularBuffer_freeFunction · 0.85

Calls 1

CircularBuffer_EmptyFunction · 0.85

Tested by 4

test_CircularBuffer_freeFunction · 0.68