mirror of
https://git.planet-casio.com/Lephenixnoir/JustUI.git
synced 2024-12-29 13:03: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/std/stdlib.h>
|
||||||
#include <gint/gint.h>
|
#include <gint/gint.h>
|
||||||
#include <gint/drivers/t6k11.h>
|
#include <gint/drivers/t6k11.h>
|
||||||
|
#include <gint/cpu.h>
|
||||||
|
|
||||||
/* Type identifier for jscene */
|
/* Type identifier for jscene */
|
||||||
static int jscene_type_id = -1;
|
static int jscene_type_id = -1;
|
||||||
|
@ -89,25 +90,34 @@ void jscene_render(jscene *scene)
|
||||||
|
|
||||||
jevent jscene_read_event(jscene *s)
|
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 };
|
return (jevent){ .source = NULL, .type = JSCENE_NONE };
|
||||||
|
}
|
||||||
|
|
||||||
jevent e = s->queue[s->queue_first];
|
jevent e = s->queue[s->queue_first];
|
||||||
s->queue_first = (s->queue_first + 1) % JSCENE_QUEUE_SIZE;
|
s->queue_first = (s->queue_first + 1) % JSCENE_QUEUE_SIZE;
|
||||||
|
cpu_atomic_end();
|
||||||
return e;
|
return e;
|
||||||
}
|
}
|
||||||
|
|
||||||
void jscene_queue_event(jscene *s, jevent e)
|
void jscene_queue_event(jscene *s, jevent e)
|
||||||
{
|
{
|
||||||
|
cpu_atomic_start();
|
||||||
|
|
||||||
/* Prevent filling and overflowing the queue */
|
/* Prevent filling and overflowing the queue */
|
||||||
int next = (s->queue_next + 1) % JSCENE_QUEUE_SIZE;
|
int next = (s->queue_next + 1) % JSCENE_QUEUE_SIZE;
|
||||||
if(next == s->queue_first) {
|
if(next == s->queue_first) {
|
||||||
s->lost_events++;
|
s->lost_events++;
|
||||||
return;
|
|
||||||
}
|
}
|
||||||
|
else {
|
||||||
s->queue[s->queue_next] = e;
|
s->queue[s->queue_next] = e;
|
||||||
s->queue_next = next;
|
s->queue_next = next;
|
||||||
|
}
|
||||||
|
|
||||||
|
cpu_atomic_end();
|
||||||
}
|
}
|
||||||
|
|
||||||
//---
|
//---
|
||||||
|
|
Loading…
Reference in a new issue