forked from PAWPAW-Mirror/lib_xua
Ue xassert and global assert flag
This commit is contained in:
@@ -4,12 +4,8 @@
|
|||||||
#define QUEUE_H_
|
#define QUEUE_H_
|
||||||
|
|
||||||
#include "midioutparse.h"
|
#include "midioutparse.h"
|
||||||
|
#include "xassert.h"
|
||||||
|
|
||||||
#define assert(x) asm("ecallf %0"::"r"(x));
|
|
||||||
|
|
||||||
#ifndef MIDI_ENABLE_ASSERTS
|
|
||||||
#define MIDI_ENABLE_ASSERTS 0
|
|
||||||
#endif
|
|
||||||
|
|
||||||
typedef struct queue_t {
|
typedef struct queue_t {
|
||||||
/// Read index.
|
/// Read index.
|
||||||
@@ -27,7 +23,7 @@ inline int is_power_of_2(unsigned x) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
inline void queue_init(queue_t &q, unsigned size) {
|
inline void queue_init(queue_t &q, unsigned size) {
|
||||||
assert(is_power_of_2(size)); // Keep this enabled as will be discovered duirng dev time
|
xassert(is_power_of_2(size) && "MIDI FIFO size must be a power of 2"); // Keep this enabled as will be discovered duirng dev time
|
||||||
q.rdptr = 0;
|
q.rdptr = 0;
|
||||||
q.wrptr = 0;
|
q.wrptr = 0;
|
||||||
q.size = size;
|
q.size = size;
|
||||||
@@ -46,25 +42,20 @@ inline void queue_push_word(queue_t &q, unsigned array[], unsigned data)
|
|||||||
{
|
{
|
||||||
|
|
||||||
if(queue_is_full(q)) {
|
if(queue_is_full(q)) {
|
||||||
if(MIDI_ENABLE_ASSERTS){
|
xassert(0 && "Unexpected push to MIDI queue when full");
|
||||||
assert(0);
|
// Silently drop message if asserts not enabled
|
||||||
} else {
|
|
||||||
// Drop message
|
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
}
|
|
||||||
|
|
||||||
array[q.wrptr++ & q.mask] = data;
|
array[q.wrptr++ & q.mask] = data;
|
||||||
}
|
}
|
||||||
|
|
||||||
inline unsigned queue_pop_word(queue_t &q, unsigned array[]) {
|
inline unsigned queue_pop_word(queue_t &q, unsigned array[]) {
|
||||||
if(queue_is_empty(q)){
|
if(queue_is_empty(q)){
|
||||||
if(MIDI_ENABLE_ASSERTS){
|
xassert(0 && "Unexpected pop from MIDI queue when empty");
|
||||||
assert(0);
|
// Return NULL messaqe if asserts not enabled
|
||||||
} else {
|
|
||||||
return MIDI_OUT_NULL_MESSAGE;
|
return MIDI_OUT_NULL_MESSAGE;
|
||||||
}
|
}
|
||||||
}
|
|
||||||
|
|
||||||
return array[q.rdptr++ & q.mask];
|
return array[q.rdptr++ & q.mask];
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user