62 assert(buffer != NULL);
68 pthread_rc = pthread_mutex_init(&buffer->
ring_mutex, NULL);
69 assert(pthread_rc == 0);
70 pthread_rc = pthread_cond_init(&buffer->
ring_cv, NULL);
71 assert(pthread_rc == 0);
76 buffer->
ring = malloc(size *
sizeof(
void *));
77 assert(buffer->
ring != NULL);
123 EVEL_DEBUG(
"RBR: Waiting for condition variable");
125 EVEL_DEBUG(
"RBR: Condition variable wait completed");
128 EVEL_DEBUG(
"RBR: Ring buffer read returning data at %lp", msg);
149 int items_written = 0;
150 EVEL_DEBUG(
"RBW: Ring Buffer Write message at %lp", msg);
153 EVEL_DEBUG(
"RBW: got lock. NR=%d NW=%d SZ=%d",
161 item_count += buffer->
size;
163 if (item_count < buffer->size - 1)
165 EVEL_DEBUG(
"RBW: %d items in buffer", item_count);
173 EVEL_ERROR(
"RBW: ring buffer full - unable to write event");
178 pthread_cond_signal(&buffer->
ring_cv);
180 return items_written;
#define EVEL_DEBUG(FMT,...)
void * ring_buffer_read(ring_buffer *buffer)
Read an element from a ring_buffer.
pthread_mutex_t ring_mutex
int ring_buffer_write(ring_buffer *buffer, void *msg)
Write an element into a ring_buffer.
void ring_buffer_initialize(ring_buffer *buffer, int size)
Ring buffer initialization.
#define EVEL_ERROR(FMT,...)
int ring_buffer_is_empty(ring_buffer *buffer)
Tests whether there is data in the ring_buffer.