1CK_RING_ENQUEUE_SPMC_... BSD Library Functions Manual CK_RING_ENQUEUE_SPMC_...
2

NAME

4     ck_ring_enqueue_spmc_size — enqueue pointer into bounded FIFO and return
5     size of buffer
6

LIBRARY

8     Concurrency Kit (libck, -lck)
9

SYNOPSIS

11     #include <ck_ring.h>
12
13     bool
14     ck_ring_enqueue_spmc_size(ck_ring_t *ring, ck_ring_buffer_t *buffer,
15         void *entry, unsigned int *length);
16

DESCRIPTION

18     The ck_ring_enqueue_spmc(3) function enqueues the pointer entry into the
19     bounded buffer pointed to by ring in FIFO fashion.  The buffer pointed to
20     by buffer must be unique to ring and point to an array of ck_ring_buf‐
21     fer_t of sufficient length (according to the power-of-2 elements in the
22     buffer).  The decoupling of the ring from the buffer serves to address
23     use-cases involving multiple address spaces and DMA, among others.  If
24     you are on non-POSIX platforms or wish for strict compliance with C, then
25     it is recommended to pass a pointer of type void ** for entry.  This
26     function is safe to call without locking for UINT_MAX concurrent invoca‐
27     tions of ck_ring_dequeue_spmc(3) or ck_ring_trydequeue_spmc(3).  This
28     function provides wait-free progress guarantees for one active invoca‐
29     tion.
30

EXAMPLE

32           #include <ck_ring.h>
33
34           /* This ring was previously initialized with ck_ring_init. */
35           ck_ring_t ring;
36
37           /* The ring was initialized for 1023 elements. */
38           ck_ring_buffer_t buffer[1024];
39
40           void
41           enqueue(void)
42           {
43                   void *entry = some_object;
44                   unsigned int length;
45
46                   /* Attempt to enqueue pointer to some_object into buffer. */
47                   if (ck_ring_enqueue_spmc_size(&ring, &buffer, &entry, &length) == false) {
48                           /*
49                            * The buffer was full and the enqueue operation
50                            * has failed.
51                            */
52                           return;
53                   }
54
55                   /*
56                    * If entry was the 101st or greater pointer in the buffer,
57                    * do something.
58                    */
59                   if (length > 100) {
60                           do_something;
61                   }
62
63                   return;
64           }
65

RETURN VALUES

67     The function returns true if the value of entry was successfully enqueued
68     into ring.  The function will return false if the value of entry could
69     not be enqueued which only occurs if ring was full. The number of entries
70     in the buffer with respect to the point in time that entry is enqueued is
71     stored in the integer pointed to by length.
72

SEE ALSO

74     ck_ring_init(3), ck_ring_dequeue_spmc(3), ck_ring_trydequeue_spmc(3),
75     ck_ring_enqueue_spmc(3), ck_ring_dequeue_spsc(3),
76     ck_ring_enqueue_spsc(3), ck_ring_enqueue_spsc_size(3),
77     ck_ring_capacity(3), ck_ring_size(3)
78
79     Additional information available at http://concurrencykit.org/
80
81                                April 20, 2013
Impressum