Antonio Nino Diaz | 9bf1d23 | 2018-11-08 09:21:48 +0000 | [diff] [blame] | 1 | /* |
| 2 | * Copyright (c) 2018, Arm Limited. All rights reserved. |
| 3 | * |
| 4 | * SPDX-License-Identifier: BSD-3-Clause |
| 5 | */ |
| 6 | |
| 7 | #ifndef SPRT_QUEUE_H |
| 8 | #define SPRT_QUEUE_H |
| 9 | |
| 10 | #include <stdint.h> |
| 11 | |
| 12 | /* Struct that defines a queue. Not to be used directly. */ |
| 13 | struct __attribute__((__packed__)) sprt_queue { |
| 14 | uint32_t entry_num; /* Number of entries */ |
| 15 | uint32_t entry_size; /* Size of an entry */ |
| 16 | uint32_t idx_write; /* Index of first empty entry */ |
| 17 | uint32_t idx_read; /* Index of first entry to read */ |
| 18 | uint8_t data[0]; /* Start of data */ |
| 19 | }; |
| 20 | |
| 21 | #define SPRT_QUEUE_HEADER_SIZE (sizeof(struct sprt_queue)) |
| 22 | |
| 23 | /* |
| 24 | * Initializes a memory region to be used as a queue of the given number of |
| 25 | * entries with the specified size. |
| 26 | */ |
| 27 | void sprt_queue_init(void *queue_base, uint32_t entry_num, uint32_t entry_size); |
| 28 | |
| 29 | /* Returns 1 if the queue is empty, 0 otherwise */ |
| 30 | int sprt_queue_is_empty(void *queue_base); |
| 31 | |
| 32 | /* Returns 1 if the queue is full, 0 otherwise */ |
| 33 | int sprt_queue_is_full(void *queue_base); |
| 34 | |
| 35 | /* |
| 36 | * Pushes a new entry intro the queue. Returns 0 on success, -ENOMEM if the |
| 37 | * queue is full. |
| 38 | */ |
| 39 | int sprt_queue_push(void *queue_base, const void *entry); |
| 40 | |
| 41 | /* |
| 42 | * Pops an entry from the queue. Returns 0 on success, -ENOENT if the queue is |
| 43 | * empty. |
| 44 | */ |
| 45 | int sprt_queue_pop(void *queue_base, void *entry); |
| 46 | |
| 47 | #endif /* SPRT_QUEUE_H */ |