Branch data Line data Source code
1 : : /* SPDX-License-Identifier: BSD-3-Clause 2 : : * Copyright (C) 2018 Intel Corporation. 3 : : * All rights reserved. 4 : : * Copyright (c) 2022 NVIDIA CORPORATION & AFFILIATES. All rights reserved. 5 : : */ 6 : : 7 : : #ifndef __REDUCE_STACK_H_ 8 : : #define __REDUCE_STACK_H_ 9 : : 10 : : #include "spdk/stdinc.h" 11 : : 12 : : #define REDUCE_QUEUE_CAPACITY_SIZE 32 13 : : 14 : : struct reduce_queue { 15 : : uint64_t items[REDUCE_QUEUE_CAPACITY_SIZE]; 16 : : uint32_t head; 17 : : uint32_t tail; 18 : : }; 19 : : 20 : : static inline void 21 : 922 : queue_init(struct reduce_queue *queue) 22 : : { 23 : 922 : queue->head = queue->tail = 0; 24 : 922 : } 25 : : 26 : : static inline bool 27 : 941958 : queue_empty(struct reduce_queue *queue) 28 : : { 29 : 941958 : return queue->head == queue->tail; 30 : : } 31 : : 32 : : static inline bool 33 : 830004 : queue_full(struct reduce_queue *queue) 34 : : { 35 : 830004 : return (queue->head == ((queue->tail + 1) % REDUCE_QUEUE_CAPACITY_SIZE)); 36 : : } 37 : : 38 : : static inline bool 39 : 830004 : queue_enqueue(struct reduce_queue *queue, uint64_t value) 40 : : { 41 [ + + ]: 830004 : if (queue_full(queue)) { 42 : 580 : return false; 43 : : } 44 : : 45 : 829424 : queue->items[queue->tail] = value; 46 : 829424 : queue->tail = (queue->tail + 1) % REDUCE_QUEUE_CAPACITY_SIZE; 47 : 829424 : return true; 48 : : } 49 : : 50 : : static inline bool 51 : 941958 : queue_dequeue(struct reduce_queue *queue, uint64_t *value) 52 : : { 53 [ + + ]: 941958 : if (queue_empty(queue)) { 54 : 113172 : return false; 55 : : } 56 : : 57 : 828786 : *value = queue->items[queue->head]; 58 : 828786 : queue->head = (queue->head + 1) % REDUCE_QUEUE_CAPACITY_SIZE; 59 : 828786 : return true; 60 : : } 61 : : 62 : : static inline uint32_t 63 : : queue_size(struct reduce_queue *queue) 64 : : { 65 : : return (queue->tail + REDUCE_QUEUE_CAPACITY_SIZE - queue->head) % REDUCE_QUEUE_CAPACITY_SIZE; 66 : : } 67 : : 68 : : #endif /* __REDUCE_STACK_H_ */