| 247 | #endif |
| 248 | |
| 249 | int |
| 250 | ifmp_ring_alloc(struct ifmp_ring **pr, int size, void *cookie, mp_ring_drain_t drain, |
| 251 | mp_ring_can_drain_t can_drain, struct malloc_type *mt, int flags) |
| 252 | { |
| 253 | struct ifmp_ring *r; |
| 254 | |
| 255 | /* All idx are 16b so size can be 65536 at most */ |
| 256 | if (pr == NULL || size < 2 || size > 65536 || drain == NULL || |
| 257 | can_drain == NULL) |
| 258 | return (EINVAL); |
| 259 | *pr = NULL; |
| 260 | flags &= M_NOWAIT | M_WAITOK; |
| 261 | MPASS(flags != 0); |
| 262 | |
| 263 | r = malloc(__offsetof(struct ifmp_ring, items[size]), mt, flags | M_ZERO); |
| 264 | if (r == NULL) |
| 265 | return (ENOMEM); |
| 266 | r->size = size; |
| 267 | r->cookie = cookie; |
| 268 | r->mt = mt; |
| 269 | r->drain = drain; |
| 270 | r->can_drain = can_drain; |
| 271 | r->enqueues = counter_u64_alloc(flags); |
| 272 | r->drops = counter_u64_alloc(flags); |
| 273 | r->starts = counter_u64_alloc(flags); |
| 274 | r->stalls = counter_u64_alloc(flags); |
| 275 | r->restarts = counter_u64_alloc(flags); |
| 276 | r->abdications = counter_u64_alloc(flags); |
| 277 | if (r->enqueues == NULL || r->drops == NULL || r->starts == NULL || |
| 278 | r->stalls == NULL || r->restarts == NULL || |
| 279 | r->abdications == NULL) { |
| 280 | ifmp_ring_free(r); |
| 281 | return (ENOMEM); |
| 282 | } |
| 283 | |
| 284 | *pr = r; |
| 285 | #ifdef MP_RING_NO_64BIT_ATOMICS |
| 286 | mtx_init(&r->lock, "mp_ring lock", NULL, MTX_DEF); |
| 287 | #endif |
| 288 | return (0); |
| 289 | } |
| 290 | |
| 291 | void |
| 292 | ifmp_ring_free(struct ifmp_ring *r) |
no test coverage detected