• Home
  • Raw
  • Download

Lines Matching refs:ringbuffer

54 	deRingbuffer* ringbuffer = (deRingbuffer*)deCalloc(sizeof(deRingbuffer));  in deRingbuffer_create()  local
56 DE_ASSERT(ringbuffer); in deRingbuffer_create()
60 ringbuffer->blockSize = blockSize; in deRingbuffer_create()
61 ringbuffer->blockCount = blockCount; in deRingbuffer_create()
62 ringbuffer->buffer = (deUint8*)deMalloc(sizeof(deUint8) * blockSize * blockCount); in deRingbuffer_create()
63 ringbuffer->blockUsage = (deInt32*)deMalloc(sizeof(deUint32) * blockCount); in deRingbuffer_create()
64 ringbuffer->emptyCount = deSemaphore_create(ringbuffer->blockCount, DE_NULL); in deRingbuffer_create()
65 ringbuffer->fullCount = deSemaphore_create(0, DE_NULL); in deRingbuffer_create()
67 if (!ringbuffer->buffer || in deRingbuffer_create()
68 !ringbuffer->blockUsage || in deRingbuffer_create()
69 !ringbuffer->emptyCount || in deRingbuffer_create()
70 !ringbuffer->fullCount) in deRingbuffer_create()
72 if (ringbuffer->emptyCount) in deRingbuffer_create()
73 deSemaphore_destroy(ringbuffer->emptyCount); in deRingbuffer_create()
74 if (ringbuffer->fullCount) in deRingbuffer_create()
75 deSemaphore_destroy(ringbuffer->fullCount); in deRingbuffer_create()
76 deFree(ringbuffer->buffer); in deRingbuffer_create()
77 deFree(ringbuffer->blockUsage); in deRingbuffer_create()
78 deFree(ringbuffer); in deRingbuffer_create()
82 memset(ringbuffer->blockUsage, 0, sizeof(deInt32) * blockCount); in deRingbuffer_create()
84 ringbuffer->outBlock = 0; in deRingbuffer_create()
85 ringbuffer->outPos = 0; in deRingbuffer_create()
87 ringbuffer->inBlock = 0; in deRingbuffer_create()
88 ringbuffer->inPos = 0; in deRingbuffer_create()
90 ringbuffer->stopNotified = DE_FALSE; in deRingbuffer_create()
91 ringbuffer->consumerStopping = DE_FALSE; in deRingbuffer_create()
93 return ringbuffer; in deRingbuffer_create()
96 void deRingbuffer_stop (deRingbuffer* ringbuffer) in deRingbuffer_stop() argument
99 ringbuffer->stopNotified = DE_TRUE; in deRingbuffer_stop()
100 deSemaphore_increment(ringbuffer->fullCount); in deRingbuffer_stop()
103 void deRingbuffer_destroy (deRingbuffer* ringbuffer) in deRingbuffer_destroy() argument
105 deSemaphore_destroy(ringbuffer->emptyCount); in deRingbuffer_destroy()
106 deSemaphore_destroy(ringbuffer->fullCount); in deRingbuffer_destroy()
108 free(ringbuffer->buffer); in deRingbuffer_destroy()
109 free(ringbuffer->blockUsage); in deRingbuffer_destroy()
110 free(ringbuffer); in deRingbuffer_destroy()
115 deRingbuffer* ringbuffer = (deRingbuffer*)stream; in producerStream_write() local
119 if (ringbuffer->stopNotified) in producerStream_write()
135 if (ringbuffer->inPos == 0) in producerStream_write()
137 deSemaphore_decrement(ringbuffer->emptyCount); in producerStream_write()
140 writeSize = deMin32(ringbuffer->blockSize - ringbuffer->inPos, bufSize - *written); in producerStream_write()
141 dst = ringbuffer->buffer + ringbuffer->blockSize * ringbuffer->inBlock + ringbuffer->inPos; in producerStream_write()
146 ringbuffer->inPos += writeSize; in producerStream_write()
148 ringbuffer->blockUsage[ringbuffer->inBlock] += writeSize; in producerStream_write()
151 if (ringbuffer->inPos == ringbuffer->blockSize) in producerStream_write()
153 ringbuffer->inPos = 0; in producerStream_write()
154 ringbuffer->inBlock++; in producerStream_write()
156 if (ringbuffer->inBlock == ringbuffer->blockCount) in producerStream_write()
157 ringbuffer->inBlock = 0; in producerStream_write()
158 deSemaphore_increment(ringbuffer->fullCount); in producerStream_write()
167 deRingbuffer* ringbuffer = (deRingbuffer*)stream; in producerStream_flush() local
172 if (ringbuffer->inPos == 0) in producerStream_flush()
175 ringbuffer->inPos = 0; in producerStream_flush()
176 ringbuffer->inBlock++; in producerStream_flush()
178 if (ringbuffer->inBlock == ringbuffer->blockCount) in producerStream_flush()
179 ringbuffer->inBlock = 0; in producerStream_flush()
181 deSemaphore_increment(ringbuffer->fullCount); in producerStream_flush()
197 deRingbuffer* ringbuffer = (deRingbuffer*)stream; in consumerStream_read() local
202 DE_ASSERT(ringbuffer); in consumerStream_read()
211 if (ringbuffer->outPos == 0) in consumerStream_read()
216 if (ringbuffer->consumerStopping) in consumerStream_read()
219 if (!deSemaphore_tryDecrement(ringbuffer->fullCount)) in consumerStream_read()
227 deSemaphore_decrement(ringbuffer->fullCount); in consumerStream_read()
229 if (ringbuffer->stopNotified) in consumerStream_read()
231 ringbuffer->consumerStopping = DE_TRUE; in consumerStream_read()
237 …writeSize = deMin32(ringbuffer->blockUsage[ringbuffer->outBlock] - ringbuffer->outPos, bufSize - *… in consumerStream_read()
238 src = ringbuffer->buffer + ringbuffer->blockSize * ringbuffer->outBlock + ringbuffer->outPos; in consumerStream_read()
243 ringbuffer->outPos += writeSize; in consumerStream_read()
247 if (ringbuffer->outPos == ringbuffer->blockUsage[ringbuffer->outBlock]) in consumerStream_read()
249 ringbuffer->blockUsage[ringbuffer->outBlock] = 0; in consumerStream_read()
250 ringbuffer->outPos = 0; in consumerStream_read()
251 ringbuffer->outBlock++; in consumerStream_read()
253 if (ringbuffer->outBlock == ringbuffer->blockCount) in consumerStream_read()
254 ringbuffer->outBlock = 0; in consumerStream_read()
256 deSemaphore_increment(ringbuffer->emptyCount); in consumerStream_read()