| | 53 | @brief Single-reader single-writer lock-free ring buffer |
| | 54 | |
| | 55 | PaUtilRingBuffer is a ring buffer used to transport samples between |
| | 56 | different execution contexts (threads, OS callbacks, interrupt handlers) |
| | 57 | without requiring the use of any locks. This only works when there is |
| | 58 | a single reader and a single writer (ie. one thread or callback writes |
| | 59 | to the ring buffer, another thread or callback reads from it). |
| | 60 | |
| | 61 | The PaUtilRingBuffer structure manages a ring buffer containing N |
| | 62 | elements, where N must be a power of two. An element may be any size |
| | 63 | (specified in bytes). |
| | 64 | |
| | 65 | The memory area used to store the buffer elements must be allocated by |
| | 66 | the client prior to calling PaUtil_InitializeRingBuffer() and must outlive |
| | 67 | the use of the ring buffer. |
| 62 | | long bufferSize; /* Number of elements in FIFO. Power of 2. Set by PaUtil_InitRingBuffer. */ |
| 63 | | long writeIndex; /* Index of next writable element. Set by PaUtil_AdvanceRingBufferWriteIndex. */ |
| 64 | | long readIndex; /* Index of next readable element. Set by PaUtil_AdvanceRingBufferReadIndex. */ |
| 65 | | long bigMask; /* Used for wrapping indices with extra bit to distinguish full/empty. */ |
| 66 | | long smallMask; /* Used for fitting indices to buffer. */ |
| 67 | | long elementSizeBytes; /* Number of bytes per element. */ |
| 68 | | char *buffer; |
| | 77 | long bufferSize; /**< Number of elements in FIFO. Power of 2. Set by PaUtil_InitRingBuffer. */ |
| | 78 | long writeIndex; /**< Index of next writable element. Set by PaUtil_AdvanceRingBufferWriteIndex. */ |
| | 79 | long readIndex; /**< Index of next readable element. Set by PaUtil_AdvanceRingBufferReadIndex. */ |
| | 80 | long bigMask; /**< Used for wrapping indices with extra bit to distinguish full/empty. */ |
| | 81 | long smallMask; /**< Used for fitting indices to buffer. */ |
| | 82 | long elementSizeBytes; /**< Number of bytes per element. */ |
| | 83 | char *buffer; /**< Pointer to the buffer containing the actual data. */ |