| 1 |
.\" |
| 2 |
.\" Copyright 2012-2013 Samy Al Bahra. |
| 3 |
.\" All rights reserved. |
| 4 |
.\" |
| 5 |
.\" Redistribution and use in source and binary forms, with or without |
| 6 |
.\" modification, are permitted provided that the following conditions |
| 7 |
.\" are met: |
| 8 |
.\" 1. Redistributions of source code must retain the above copyright |
| 9 |
.\" notice, this list of conditions and the following disclaimer. |
| 10 |
.\" 2. Redistributions in binary form must reproduce the above copyright |
| 11 |
.\" notice, this list of conditions and the following disclaimer in the |
| 12 |
.\" documentation and/or other materials provided with the distribution. |
| 13 |
.\" |
| 14 |
.\" THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND |
| 15 |
.\" ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE |
| 16 |
.\" IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE |
| 17 |
.\" ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE |
| 18 |
.\" FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL |
| 19 |
.\" DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS |
| 20 |
.\" OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) |
| 21 |
.\" HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT |
| 22 |
.\" LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY |
| 23 |
.\" OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF |
| 24 |
.\" SUCH DAMAGE. |
| 25 |
.\" |
| 26 |
.\" |
| 27 |
.Dd April 20, 2013 |
| 28 |
.Dt CK_RING_ENQUEUE_SPMC_SIZE 3 |
| 29 |
.Sh NAME |
| 30 |
.Nm ck_ring_enqueue_spmc_size |
| 31 |
.Nd enqueue pointer into bounded FIFO and return size of buffer |
| 32 |
.Sh LIBRARY |
| 33 |
Concurrency Kit (libck, \-lck) |
| 34 |
.Sh SYNOPSIS |
| 35 |
.In ck_ring.h |
| 36 |
.Ft bool |
| 37 |
.Fn ck_ring_enqueue_spmc_size "ck_ring_t *ring" "ck_ring_buffer_t *buffer" "void *entry" "unsigned int *length" |
| 38 |
.Sh DESCRIPTION |
| 39 |
The |
| 40 |
.Fn ck_ring_enqueue_spmc 3 |
| 41 |
function enqueues the pointer |
| 42 |
.Fa entry |
| 43 |
into the bounded buffer pointed to by |
| 44 |
.Fa ring |
| 45 |
in FIFO fashion. |
| 46 |
The buffer pointed to by |
| 47 |
.Fa buffer |
| 48 |
must be unique to |
| 49 |
.Fa ring |
| 50 |
and point to an array of ck_ring_buffer_t of sufficient |
| 51 |
length (according to the power-of-2 elements in the buffer). |
| 52 |
The decoupling of the ring from the buffer serves |
| 53 |
to address use-cases involving multiple address spaces |
| 54 |
and DMA, among others. |
| 55 |
If you are on non-POSIX platforms or wish for strict |
| 56 |
compliance with C, then it is recommended to pass a |
| 57 |
pointer of type void ** for |
| 58 |
.Fa entry . |
| 59 |
This function is safe to call without locking for UINT_MAX |
| 60 |
concurrent invocations of |
| 61 |
.Fn ck_ring_dequeue_spmc 3 |
| 62 |
or |
| 63 |
.Fn ck_ring_trydequeue_spmc 3 . |
| 64 |
This function provides wait-free progress |
| 65 |
guarantees for one active invocation. |
| 66 |
.Sh EXAMPLE |
| 67 |
.Bd -literal -offset indent |
| 68 |
#include <ck_ring.h> |
| 69 |
|
| 70 |
/* This ring was previously initialized with ck_ring_init. */ |
| 71 |
ck_ring_t ring; |
| 72 |
|
| 73 |
/* The ring was initialized for 1023 elements. */ |
| 74 |
ck_ring_buffer_t buffer[1024]; |
| 75 |
|
| 76 |
void |
| 77 |
enqueue(void) |
| 78 |
{ |
| 79 |
void *entry = some_object; |
| 80 |
unsigned int length; |
| 81 |
|
| 82 |
/* Attempt to enqueue pointer to some_object into buffer. */ |
| 83 |
if (ck_ring_enqueue_spmc_size(&ring, &buffer, &entry, &length) == false) { |
| 84 |
/* |
| 85 |
* The buffer was full and the enqueue operation |
| 86 |
* has failed. |
| 87 |
*/ |
| 88 |
return; |
| 89 |
} |
| 90 |
|
| 91 |
/* |
| 92 |
* If entry was the 101st or greater pointer in the buffer, |
| 93 |
* do something. |
| 94 |
*/ |
| 95 |
if (length > 100) { |
| 96 |
do_something; |
| 97 |
} |
| 98 |
|
| 99 |
return; |
| 100 |
} |
| 101 |
.Ed |
| 102 |
.Sh RETURN VALUES |
| 103 |
The function returns true if the value of |
| 104 |
.Fa entry |
| 105 |
was successfully enqueued into |
| 106 |
.Fa ring . |
| 107 |
The function will return false if the value of |
| 108 |
.Fa entry |
| 109 |
could not be enqueued which only occurs if |
| 110 |
.Fa ring |
| 111 |
was full. The number of entries in the buffer |
| 112 |
with respect to the point in time that |
| 113 |
.Fa entry |
| 114 |
is enqueued is stored in the integer pointed to by |
| 115 |
.Fa length . |
| 116 |
.Sh SEE ALSO |
| 117 |
.Xr ck_ring_init 3 , |
| 118 |
.Xr ck_ring_dequeue_spmc 3 , |
| 119 |
.Xr ck_ring_trydequeue_spmc 3 , |
| 120 |
.Xr ck_ring_enqueue_spmc 3 , |
| 121 |
.Xr ck_ring_dequeue_spsc 3 , |
| 122 |
.Xr ck_ring_enqueue_spsc 3 , |
| 123 |
.Xr ck_ring_enqueue_spsc_size 3 , |
| 124 |
.Xr ck_ring_capacity 3 , |
| 125 |
.Xr ck_ring_size 3 |
| 126 |
.Pp |
| 127 |
Additional information available at http://concurrencykit.org/ |