summaryrefslogtreecommitdiff
path: root/src/util
diff options
context:
space:
mode:
Diffstat (limited to 'src/util')
-rw-r--r--src/util/blocking_ring_buffer.c46
-rw-r--r--src/util/blocking_ring_buffer.h6
-rw-r--r--src/util/color_palette.c14
-rw-r--r--src/util/queue.h24
4 files changed, 45 insertions, 45 deletions
diff --git a/src/util/blocking_ring_buffer.c b/src/util/blocking_ring_buffer.c
index 5cc3325..ec6cbb8 100644
--- a/src/util/blocking_ring_buffer.c
+++ b/src/util/blocking_ring_buffer.c
@@ -4,17 +4,17 @@
#define LOCK(n) \
buffer->req_start = n; \
- aki_cond_wait(&buffer->cond, &buffer->mutex);
+ nn_cond_wait(&buffer->cond, &buffer->mutex);
#define SIGNAL() \
- aki_cond_signal(&buffer->cond);
+ nn_cond_signal(&buffer->cond);
void camu_ring_buffer_init(struct camu_ring_buffer *buffer, s32 size)
{
buffer->size = size;
buffer->data = (u8 *)al_malloc(buffer->size);
- aki_mutex_init(&buffer->mutex);
- aki_cond_init(&buffer->cond);
+ nn_mutex_init(&buffer->mutex);
+ nn_cond_init(&buffer->cond);
camu_ring_buffer_reset(buffer);
buffer->reset_unlock = false;
buffer->enabled = true;
@@ -23,71 +23,71 @@ void camu_ring_buffer_init(struct camu_ring_buffer *buffer, s32 size)
// TODO: does locking here actually prevent this from messing something up.
void camu_ring_buffer_reset(struct camu_ring_buffer *buffer)
{
- aki_mutex_lock(&buffer->mutex);
+ nn_mutex_lock(&buffer->mutex);
buffer->valid_size = 0;
buffer->start = 0;
buffer->end = 0;
// If get_chunk was waiting it doesn't matter where req_start
// was, there should be room now.
- if (aki_cond_is_waiting(&buffer->cond)) {
+ if (nn_cond_is_waiting(&buffer->cond)) {
buffer->reset_unlock = true;
SIGNAL();
}
buffer->wrap = false;
- aki_mutex_unlock(&buffer->mutex);
+ nn_mutex_unlock(&buffer->mutex);
}
void camu_ring_buffer_disable(struct camu_ring_buffer *buffer)
{
- aki_mutex_lock(&buffer->mutex);
+ nn_mutex_lock(&buffer->mutex);
buffer->enabled = false;
// No state on the buffer will be edited by the time a get_chunk
// returns because of this. So, the next call to get_chunk after
// the buffer is re-enabled should be correct.
- if (aki_cond_is_waiting(&buffer->cond)) {
+ if (nn_cond_is_waiting(&buffer->cond)) {
buffer->reset_unlock = true;
SIGNAL();
}
- aki_mutex_unlock(&buffer->mutex);
+ nn_mutex_unlock(&buffer->mutex);
}
void camu_ring_buffer_enable(struct camu_ring_buffer *buffer)
{
- aki_mutex_lock(&buffer->mutex);
+ nn_mutex_lock(&buffer->mutex);
buffer->enabled = true;
- aki_mutex_unlock(&buffer->mutex);
+ nn_mutex_unlock(&buffer->mutex);
}
s32 camu_ring_buffer_space(struct camu_ring_buffer *buffer)
{
s32 available = 0;
- aki_mutex_lock(&buffer->mutex);
+ nn_mutex_lock(&buffer->mutex);
if (buffer->end < buffer->start) {
available = buffer->start - buffer->end;
} else {
available = buffer->size - buffer->end;
}
- aki_mutex_unlock(&buffer->mutex);
+ nn_mutex_unlock(&buffer->mutex);
return available;
}
s32 camu_ring_buffer_occupied(struct camu_ring_buffer *buffer)
{
s32 filled = 0;
- aki_mutex_lock(&buffer->mutex);
+ nn_mutex_lock(&buffer->mutex);
if (buffer->end < buffer->start) {
filled = (buffer->valid_size - buffer->start) + buffer->end;
} else {
// If the buffer is empty this will equate to 0.
filled = buffer->end - buffer->start;
}
- aki_mutex_unlock(&buffer->mutex);
+ nn_mutex_unlock(&buffer->mutex);
return filled;
}
u8 *camu_ring_buffer_get_chunk(struct camu_ring_buffer *buffer, s32 n)
{
- aki_mutex_lock(&buffer->mutex);
+ nn_mutex_lock(&buffer->mutex);
if (!buffer->enabled) return NULL;
@@ -136,7 +136,7 @@ u8 *camu_ring_buffer_get_chunk(struct camu_ring_buffer *buffer, s32 n)
s32 camu_ring_buffer_read(struct camu_ring_buffer *buffer, u8 **data, s32 n)
{
- aki_mutex_lock(&buffer->mutex);
+ nn_mutex_lock(&buffer->mutex);
// Set data even if we are going to read 0 bytes to avoid possible issues
// with data being NULL after a call to read.
@@ -164,11 +164,11 @@ s32 camu_ring_buffer_read(struct camu_ring_buffer *buffer, u8 **data, s32 n)
buffer->start = 0;
buffer->valid_size = 0;
// We wrapped and aren't specifically waiting for a position after the wrap, so unlock.
- if (aki_cond_is_waiting(&buffer->cond) && !buffer->wrap) {
+ if (nn_cond_is_waiting(&buffer->cond) && !buffer->wrap) {
SIGNAL();
}
buffer->wrap = false;
- } else if (aki_cond_is_waiting(&buffer->cond) && (!buffer->wrap && buffer->start > buffer->req_start)) {
+ } else if (nn_cond_is_waiting(&buffer->cond) && (!buffer->wrap && buffer->start > buffer->req_start)) {
// We read past the position we were waiting for, so unlock.
SIGNAL();
}
@@ -182,12 +182,12 @@ s32 camu_ring_buffer_read(struct camu_ring_buffer *buffer, u8 **data, s32 n)
// only after the pointer has been used.
void camu_ring_buffer_unlock(struct camu_ring_buffer *buffer)
{
- aki_mutex_unlock(&buffer->mutex);
+ nn_mutex_unlock(&buffer->mutex);
}
void camu_ring_buffer_free(struct camu_ring_buffer *buffer)
{
if (buffer->data) al_free(buffer->data);
- aki_mutex_destroy(&buffer->mutex);
- aki_cond_destroy(&buffer->cond);
+ nn_mutex_destroy(&buffer->mutex);
+ nn_cond_destroy(&buffer->cond);
}
diff --git a/src/util/blocking_ring_buffer.h b/src/util/blocking_ring_buffer.h
index ff3521e..a5288d0 100644
--- a/src/util/blocking_ring_buffer.h
+++ b/src/util/blocking_ring_buffer.h
@@ -1,7 +1,7 @@
#pragma once
#include <al/types.h>
-#include <aki/thread.h>
+#include <nnwt/thread.h>
// Ring buffer with blocking write and non-blocking read.
// - Write can block and always returns the exact amount requested.
@@ -20,8 +20,8 @@ struct camu_ring_buffer {
// True if we need to wait for the start to wrap around
// to the begining before considering signaling.
bool wrap;
- struct aki_mutex mutex;
- struct aki_cond cond;
+ struct nn_mutex mutex;
+ struct nn_cond cond;
// Signal get_chunk to return null and not modifiy the buffer
// if it was blocking and reset was called.
bool reset_unlock;
diff --git a/src/util/color_palette.c b/src/util/color_palette.c
index cc7f5b5..b67f1bb 100644
--- a/src/util/color_palette.c
+++ b/src/util/color_palette.c
@@ -1,7 +1,7 @@
#include "color_palette.h"
-#ifdef AKIYO_HAS_JSON
-#include <aki/file.h>
+#ifdef NAUNET_HAS_JSON
+#include <nnwt/file.h>
#include <jansson.h>
static char *special_colors[2] = {
@@ -33,14 +33,14 @@ struct camu_color_palette global_color_palette = { 0 };
bool camu_color_palette_init(str *path)
{
-#ifdef AKIYO_HAS_JSON
- struct aki_file file;
- if (!aki_file_open(&file, path, 0)) {
+#ifdef NAUNET_HAS_JSON
+ struct nn_file file;
+ if (!nn_file_open(&file, path, 0)) {
return false;
}
str s;
- aki_file_read_as_str(&file, &s);
- aki_file_close(&file);
+ nn_file_read_as_str(&file, &s);
+ nn_file_close(&file);
json_error_t error;
json_t *root = json_loadb(s.data, s.len, 0, &error);
if (!root) return false;
diff --git a/src/util/queue.h b/src/util/queue.h
index 4f184ba..ac0dfec 100644
--- a/src/util/queue.h
+++ b/src/util/queue.h
@@ -1,53 +1,53 @@
#pragma once
#include <al/array.h>
-#include <aki/thread.h>
+#include <nnwt/thread.h>
#define queue(type) \
struct { \
array(type) a; \
- struct aki_mutex mutex; \
+ struct nn_mutex mutex; \
}
#define camu_queue_size(q, r) \
do { \
- aki_mutex_lock(&(q).mutex); \
+ nn_mutex_lock(&(q).mutex); \
r = (q).a.size; \
- aki_mutex_unlock(&(q).mutex); \
+ nn_mutex_unlock(&(q).mutex); \
} while (0)
#define camu_queue_init(q) \
do { \
al_array_init((q).a); \
- aki_mutex_init(&(q).mutex); \
+ nn_mutex_init(&(q).mutex); \
} while (0)
#define camu_queue_push(q, item) \
do { \
- aki_mutex_lock(&(q).mutex); \
+ nn_mutex_lock(&(q).mutex); \
al_array_push((q).a, item); \
- aki_mutex_unlock(&(q).mutex); \
+ nn_mutex_unlock(&(q).mutex); \
} while (0)
#define camu_queue_pop(q, r) \
do { \
- aki_mutex_lock(&(q).mutex); \
+ nn_mutex_lock(&(q).mutex); \
al_array_pop_at((q).a, 0, r); \
- aki_mutex_unlock(&(q).mutex); \
+ nn_mutex_unlock(&(q).mutex); \
} while (0)
#define camu_queue_try_pop(q, s, r) \
do { \
- aki_mutex_lock(&(q).mutex); \
+ nn_mutex_lock(&(q).mutex); \
s = (q).a.size; \
if (s > 0) { \
al_array_pop_at((q).a, 0, r); \
} \
- aki_mutex_unlock(&(q).mutex); \
+ nn_mutex_unlock(&(q).mutex); \
} while (0)
#define camu_queue_free(q) \
do { \
- aki_mutex_destroy(&(q).mutex); \
+ nn_mutex_destroy(&(q).mutex); \
al_array_free((q).a); \
} while (0)