43 #ifndef TPCircularBuffer_h
44 #define TPCircularBuffer_h
46 #include <libkern/OSAtomic.h>
48 #include <winpr/assert.h>
61 volatile int32_t fillCount;
105 static __inline__ __attribute__((always_inline))
void*
108 *availableBytes = buffer->fillCount;
109 if (*availableBytes == 0)
111 return (
void*)((
char*)buffer->buffer + buffer->tail);
122 static __inline__ __attribute__((always_inline))
void
125 buffer->tail = (buffer->tail + amount) % buffer->length;
126 OSAtomicAdd32Barrier(-amount, &buffer->fillCount);
127 WINPR_ASSERT(buffer->fillCount >= 0);
134 static __inline__ __attribute__((always_inline))
void
137 buffer->tail = (buffer->tail + amount) % buffer->length;
138 buffer->fillCount -= amount;
139 WINPR_ASSERT(buffer->fillCount >= 0);
152 static __inline__ __attribute__((always_inline))
void*
155 *availableBytes = (buffer->length - buffer->fillCount);
156 if (*availableBytes == 0)
158 return (
void*)((
char*)buffer->buffer + buffer->head);
171 static __inline__ __attribute__((always_inline))
void
174 buffer->head = (buffer->head + amount) % buffer->length;
175 OSAtomicAdd32Barrier(amount, &buffer->fillCount);
176 WINPR_ASSERT(buffer->fillCount <= buffer->length);
183 static __inline__ __attribute__((always_inline))
void
186 buffer->head = (buffer->head + amount) % buffer->length;
187 buffer->fillCount += amount;
188 WINPR_ASSERT(buffer->fillCount <= buffer->length);
201 static __inline__ __attribute__((always_inline))
bool
202 TPCircularBufferProduceBytes(
TPCircularBuffer* buffer,
const void* src, int32_t len)
205 void* ptr = TPCircularBufferHead(buffer, &space);
208 memcpy(ptr, src, len);
209 TPCircularBufferProduce(buffer, len);