mirror of
https://git.planet-casio.com/Lephenixnoir/JustUI.git
synced 2024-12-28 20:43:40 +01:00
jscene: atomic queue access for interrupt-safety
This commit is contained in:
parent
5e2488cdf4
commit
550c08e200
1 changed files with 14 additions and 4 deletions
16
src/jscene.c
16
src/jscene.c
|
@ -9,6 +9,7 @@
|
|||
#include <gint/std/stdlib.h>
|
||||
#include <gint/gint.h>
|
||||
#include <gint/drivers/t6k11.h>
|
||||
#include <gint/cpu.h>
|
||||
|
||||
/* Type identifier for jscene */
|
||||
static int jscene_type_id = -1;
|
||||
|
@ -89,27 +90,36 @@ void jscene_render(jscene *scene)
|
|||
|
||||
jevent jscene_read_event(jscene *s)
|
||||
{
|
||||
if(s->queue_first == s->queue_next)
|
||||
cpu_atomic_start();
|
||||
|
||||
if(s->queue_first == s->queue_next) {
|
||||
cpu_atomic_end();
|
||||
return (jevent){ .source = NULL, .type = JSCENE_NONE };
|
||||
}
|
||||
|
||||
jevent e = s->queue[s->queue_first];
|
||||
s->queue_first = (s->queue_first + 1) % JSCENE_QUEUE_SIZE;
|
||||
cpu_atomic_end();
|
||||
return e;
|
||||
}
|
||||
|
||||
void jscene_queue_event(jscene *s, jevent e)
|
||||
{
|
||||
cpu_atomic_start();
|
||||
|
||||
/* Prevent filling and overflowing the queue */
|
||||
int next = (s->queue_next + 1) % JSCENE_QUEUE_SIZE;
|
||||
if(next == s->queue_first) {
|
||||
s->lost_events++;
|
||||
return;
|
||||
}
|
||||
|
||||
else {
|
||||
s->queue[s->queue_next] = e;
|
||||
s->queue_next = next;
|
||||
}
|
||||
|
||||
cpu_atomic_end();
|
||||
}
|
||||
|
||||
//---
|
||||
// Keyboard focus and keyboard events
|
||||
//---
|
||||
|
|
Loading…
Reference in a new issue