26
26
} while (0)
27
27
#endif
28
28
29
- /**
30
- * The producer and the consumer have a head and a tail index. The particularity
29
+ /* The producer and the consumer have a head and a tail index. The particularity
31
30
* of these index is that they are not between 0 and size(ring). These indexes
32
31
* are between 0 and 2^32, and we mask their value when we access the ring[]
33
32
* field. Thanks to this assumption, we can do subtractions between 2 index
37
36
typedef struct {
38
37
struct { /** Ring producer status. */
39
38
uint32_t watermark ; /**< Maximum items before EDQUOT. */
40
- uint32_t size ; /**< Size of ring. */
41
- uint32_t mask ; /**< Mask (size - 1) of ring. */
39
+ uint32_t size ; /**< Size of ring buffer . */
40
+ uint32_t mask ; /**< Mask (size - 1) of ring buffer . */
42
41
volatile uint32_t head , tail ; /**< Producer head and tail. */
43
42
} prod __attribute__((__aligned__ (CACHE_LINE_SIZE )));
44
43
45
44
struct { /** Ring consumer status. */
46
- uint32_t size ; /**< Size of the ring. */
47
- uint32_t mask ; /**< Mask (size - 1) of ring. */
45
+ uint32_t size ; /**< Size of the ring buffer . */
46
+ uint32_t mask ; /**< Mask (size - 1) of ring buffer . */
48
47
volatile uint32_t head , tail ; /**< Consumer head and tail. */
49
48
} cons __attribute__((__aligned__ (CACHE_LINE_SIZE )));
50
49
@@ -57,19 +56,17 @@ typedef struct {
57
56
#define ALIGN_CEIL (val , align ) \
58
57
(typeof(val))((val) + (-(typeof(val))(val) & ((align) -1)))
59
58
60
-
61
- /**
62
- * Calculate the memory size needed for a ring buffer.
59
+ /* Calculate the memory size needed for a ring buffer.
63
60
*
64
61
* This function returns the number of bytes needed for a ring buffer, given
65
62
* the number of elements in it. This value is the sum of the size of the
66
63
* structure ringbuf and the size of the memory needed by the objects pointers.
67
64
* The value is aligned to a cache line size.
68
65
*
69
66
* @param count
70
- * The number of elements in the ring (must be a power of 2).
67
+ * The number of elements in the ring buffer (must be a power of 2).
71
68
* @return
72
- * - The memory size occupied by the ring on success.
69
+ * - The memory size occupied by the ring buffer on success.
73
70
* - -EINVAL if count is not a power of 2.
74
71
*/
75
72
ssize_t ringbuf_get_memsize (const unsigned count )
@@ -85,17 +82,16 @@ ssize_t ringbuf_get_memsize(const unsigned count)
85
82
return sz ;
86
83
}
87
84
88
- /**
89
- * Initialize a ring buffer.
85
+ /* Initialize a ring buffer.
90
86
*
91
87
* The ring size is set to *count*, which must be a power of two. Water
92
88
* marking is disabled by default. The real usable ring size is (count - 1)
93
- * instead of (count) to differentiate a free ring from an empty ring.
89
+ * instead of (count) to differentiate a free ring from an empty ring buffer .
94
90
*
95
91
* @param r
96
- * The pointer to the ring structure followed by the objects table.
92
+ * The pointer to the ring buffer structure followed by the objects table.
97
93
* @param count
98
- * The number of elements in the ring (must be a power of 2).
94
+ * The number of elements in the ring buffer (must be a power of 2).
99
95
* @return
100
96
* 0 on success, or a negative value on error.
101
97
*/
@@ -109,17 +105,16 @@ int ringbuf_init(ringbuf_t *r, const unsigned count)
109
105
return 0 ;
110
106
}
111
107
112
- /**
113
- * Create a ring buffer.
108
+ /* Create a ring buffer.
114
109
*
115
110
* The real usable ring size is (count - 1) instead of (count) to
116
- * differentiate a free ring from an empty ring.
111
+ * differentiate a free ring from an empty ring buffer .
117
112
*
118
113
* @param count
119
114
* The size of the ring (must be a power of 2).
120
115
* @return
121
- * On success, the pointer to the new allocated ring. NULL on error with
122
- * errno set appropriately. Possible errno values include:
116
+ * On success, the pointer to the new allocated ring buffer . NULL on error
117
+ * with errno set appropriately. Possible errno values include:
123
118
* - EINVAL - count provided is not a power of 2
124
119
* - ENOSPC - the maximum number of memzones has already been allocated
125
120
* - EEXIST - a memzone with the same name already exists
@@ -137,8 +132,7 @@ ringbuf_t *ringbuf_create(const unsigned count)
137
132
return r ;
138
133
}
139
134
140
- /**
141
- * Release all memory used by the ring.
135
+ /* Release all memory used by the ring buffer.
142
136
*
143
137
* @param r
144
138
* Ring to free
@@ -148,7 +142,7 @@ void ringbuf_free(ringbuf_t *r)
148
142
free (r );
149
143
}
150
144
151
- /* The actual enqueue of pointers on the ring.
145
+ /* The actual enqueue of pointers on the ring buffer .
152
146
* Placed here since identical code needed in both single- and multi- producer
153
147
* enqueue functions.
154
148
*/
@@ -210,16 +204,14 @@ void ringbuf_free(ringbuf_t *r)
210
204
} \
211
205
} while (0)
212
206
213
- /**
214
- * @internal Enqueue several objects on a ring buffer (NOT multi-producers
215
- * safe).
207
+ /* Enqueue several objects on a ring buffer (NOT multi-producers safe).
216
208
*
217
209
* @param r
218
- * A pointer to the ring structure.
210
+ * A pointer to the ring buffer structure.
219
211
* @param obj_table
220
212
* A pointer to a table of void * pointers (objects).
221
213
* @param n
222
- * The number of objects to add in the ring from the obj_table.
214
+ * The number of objects to add in the ring buffer from the obj_table.
223
215
* @return
224
216
* - 0: Success; objects enqueue.
225
217
* - -EDQUOT: Quota exceeded. The objects have been enqueued, but the
@@ -238,14 +230,14 @@ static inline int ringbuffer_sp_do_enqueue(ringbuf_t *r,
238
230
*/
239
231
uint32_t free_entries = mask + cons_tail - prod_head ;
240
232
241
- /* check that we have enough room in ring */
233
+ /* check that we have enough room in ring buffer */
242
234
if ((n > free_entries ))
243
235
return - ENOBUFS ;
244
236
245
237
uint32_t prod_next = prod_head + n ;
246
238
r -> prod .head = prod_next ;
247
239
248
- /* write entries in ring */
240
+ /* write entries in ring buffer */
249
241
ENQUEUE_PTRS ();
250
242
__compiler_barrier ();
251
243
@@ -255,20 +247,19 @@ static inline int ringbuffer_sp_do_enqueue(ringbuf_t *r,
255
247
return ((mask + 1 ) - free_entries + n ) > r -> prod .watermark ? - EDQUOT : 0 ;
256
248
}
257
249
258
- /**
259
- * @internal Dequeue several objects from a ring buffer (NOT multi-consumers
260
- * safe). When the request objects are more than the available objects, only
261
- * dequeue the actual number of objects
250
+ /* Dequeue several objects from a ring buffer (NOT multi-consumers safe).
251
+ * When the request objects are more than the available objects, only dequeue
252
+ * the actual number of objects
262
253
*
263
254
* @param r
264
- * A pointer to the ring structure.
255
+ * A pointer to the ring buffer structure.
265
256
* @param obj_table
266
257
* A pointer to a table of void * pointers (objects) that will be filled.
267
258
* @param n
268
- * The number of objects to dequeue from the ring to the obj_table.
259
+ * The number of objects to dequeue from the ring buffer to the obj_table.
269
260
* @return
270
261
* - 0: Success; objects dequeued.
271
- * - -ENOENT: Not enough entries in the ring to dequeue; no object is
262
+ * - -ENOENT: Not enough entries in the ring buffer to dequeue; no object is
272
263
* dequeued.
273
264
*/
274
265
static inline int ringbuffer_sc_do_dequeue (ringbuf_t * r ,
@@ -297,18 +288,18 @@ static inline int ringbuffer_sc_do_dequeue(ringbuf_t *r,
297
288
return 0 ;
298
289
}
299
290
300
- /**
301
- * Enqueue one object on a ring buffer (NOT multi-producers safe).
291
+ /* Enqueue one object on a ring buffer (NOT multi-producers safe).
302
292
*
303
293
* @param r
304
- * A pointer to the ring structure.
294
+ * A pointer to the ring buffer structure.
305
295
* @param obj
306
296
* A pointer to the object to be added.
307
297
* @return
308
298
* - 0: Success; objects enqueued.
309
299
* - -EDQUOT: Quota exceeded. The objects have been enqueued, but the
310
300
* high water mark is exceeded.
311
- * - -ENOBUFS: Not enough room in the ring to enqueue; no object is enqueued.
301
+ * - -ENOBUFS: Not enough room in the ring buffer to enqueue; no object
302
+ * is enqueued.
312
303
*/
313
304
static inline int ringbuf_sp_enqueue (ringbuf_t * r , void * obj )
314
305
{
@@ -324,16 +315,15 @@ static inline int ringbuf_sp_enqueue(ringbuf_t *r, void *obj)
324
315
* A pointer to a void * pointer (object) that will be filled.
325
316
* @return
326
317
* - 0: Success; objects dequeued.
327
- * - -ENOENT: Not enough entries in the ring to dequeue, no object is
328
- * dequeued.
318
+ * - -ENOENT: Not enough entries in the ring buffer to dequeue, no object
319
+ * is dequeued.
329
320
*/
330
321
static inline int ringbuf_sc_dequeue (ringbuf_t * r , void * * obj_p )
331
322
{
332
323
return ringbuffer_sc_do_dequeue (r , obj_p , 1 );
333
324
}
334
325
335
- /**
336
- * Test if a ring buffer is full.
326
+ /* Test if a ring buffer is full.
337
327
*
338
328
* @param r
339
329
* A pointer to the ring structure.
@@ -347,8 +337,7 @@ static inline bool ringbuf_is_full(const ringbuf_t *r)
347
337
return ((cons_tail - prod_tail - 1 ) & r -> prod .mask ) == 0 ;
348
338
}
349
339
350
- /**
351
- * Test if a ring buffer is empty.
340
+ /* Test if a ring buffer is empty.
352
341
*
353
342
* @param r
354
343
* A pointer to the ring structure.
0 commit comments