summaryrefslogtreecommitdiff
path: root/src/cache
diff options
context:
space:
mode:
Diffstat (limited to 'src/cache')
-rw-r--r--src/cache/backings/file.c30
-rw-r--r--src/cache/backings/file.h10
-rw-r--r--src/cache/backings/file_common.c12
-rw-r--r--src/cache/backings/file_mapped.c28
-rw-r--r--src/cache/backings/memory.c26
-rw-r--r--src/cache/backings/memory.h4
-rw-r--r--src/cache/entry.c14
-rw-r--r--src/cache/entry.h2
-rw-r--r--src/cache/handle.h2
-rw-r--r--src/cache/handler.h4
-rw-r--r--src/cache/handlers/cdio.c20
-rw-r--r--src/cache/handlers/cdio.h6
-rw-r--r--src/cache/handlers/file.c2
-rw-r--r--src/cache/handlers/http.c62
-rw-r--r--src/cache/handlers/http.h12
-rw-r--r--src/cache/meson.build9
-rw-r--r--src/cache/threaded_waits.c70
-rw-r--r--src/cache/wait.h6
18 files changed, 157 insertions, 162 deletions
diff --git a/src/cache/backings/file.c b/src/cache/backings/file.c
index a09d535..bf62190 100644
--- a/src/cache/backings/file.c
+++ b/src/cache/backings/file.c
@@ -6,64 +6,64 @@
static void file_backing_lock(struct cch_backing *backing)
{
struct cch_backing_file *file = (struct cch_backing_file *)backing;
- aki_mutex_lock(&file->mutex);
+ nn_mutex_lock(&file->mutex);
}
static void file_backing_write(struct cch_backing *backing, u8 *buf, off_t index, size_t *size)
{
struct cch_backing_file *file = (struct cch_backing_file *)backing;
- aki_mutex_lock(&file->mutex);
+ nn_mutex_lock(&file->mutex);
if (file->u.pointer != index) {
- file->u.pointer = aki_file_seek(&file->file, index, SEEK_SET);
+ file->u.pointer = nn_file_seek(&file->file, index, SEEK_SET);
al_assert(file->u.pointer == index);
}
if (file->size >= 0 && index + ((off_t)*size) >= file->size) {
*size = MAX(file->size - index, 0L);
}
- aki_file_write(&file->file, buf, *size);
+ nn_file_write(&file->file, buf, *size);
file->u.pointer += *size;
cch_backing_fill_range(&file->backing, index, *size);
- aki_mutex_unlock(&file->mutex);
+ nn_mutex_unlock(&file->mutex);
}
static void file_backing_read(struct cch_backing *backing, u8 *buf, off_t index, size_t *size)
{
struct cch_backing_file *file = (struct cch_backing_file *)backing;
- aki_mutex_lock(&file->mutex);
+ nn_mutex_lock(&file->mutex);
if (file->u.pointer != index) {
- file->u.pointer = aki_file_seek(&file->file, index, SEEK_SET);
+ file->u.pointer = nn_file_seek(&file->file, index, SEEK_SET);
al_assert(file->u.pointer == index);
}
if (file->size >= 0 && index + ((off_t)*size) >= file->size) {
*size = MAX(file->size - index, 0L);
}
- aki_file_read(&file->file, buf, *size);
+ nn_file_read(&file->file, buf, *size);
file->u.pointer += *size;
- aki_mutex_unlock(&file->mutex);
+ nn_mutex_unlock(&file->mutex);
}
static void file_backing_unlock(struct cch_backing *backing)
{
struct cch_backing_file *file = (struct cch_backing_file *)backing;
- aki_mutex_unlock(&file->mutex);
+ nn_mutex_unlock(&file->mutex);
}
static void file_backing_resize(struct cch_backing *backing, size_t size)
{
struct cch_backing_file *file = (struct cch_backing_file *)backing;
- aki_mutex_lock(&file->mutex);
+ nn_mutex_lock(&file->mutex);
file->size = size;
if ((off_t)size > file->filesize) {
- aki_file_truncate(&file->file, size);
+ nn_file_truncate(&file->file, size);
file->filesize = size;
}
- aki_mutex_unlock(&file->mutex);
+ nn_mutex_unlock(&file->mutex);
}
static void file_backing_free(struct cch_backing **backing)
{
struct cch_backing_file *file = (struct cch_backing_file *)*backing;
- aki_file_close(&file->file);
+ nn_file_close(&file->file);
al_array_free(file->backing.available);
al_free(file);
*backing = NULL;
@@ -87,6 +87,6 @@ struct cch_backing *cch_backing_file_create(str *path, size_t size)
return NULL;
}
file->u.pointer = 0;
- aki_mutex_init(&file->mutex);
+ nn_mutex_init(&file->mutex);
return (struct cch_backing *)file;
}
diff --git a/src/cache/backings/file.h b/src/cache/backings/file.h
index 3f8437b..8a2bf7a 100644
--- a/src/cache/backings/file.h
+++ b/src/cache/backings/file.h
@@ -1,22 +1,22 @@
#pragma once
#include <al/str.h>
-#include <aki/thread.h>
-#include <aki/common.h>
-#include <aki/file.h>
+#include <nnwt/thread.h>
+#include <nnwt/common.h>
+#include <nnwt/file.h>
#include "../backing.h"
struct cch_backing_file {
struct cch_backing backing;
- struct aki_file file;
+ struct nn_file file;
off_t size;
off_t filesize;
union {
void *map; // CACHE_BACKING_MAPPED
off_t pointer; // CACHE_BACKING_READ
} u;
- struct aki_mutex mutex;
+ struct nn_mutex mutex;
};
struct cch_backing *cch_backing_file_create(str *path, size_t filesize);
diff --git a/src/cache/backings/file_common.c b/src/cache/backings/file_common.c
index 35322fd..3914f95 100644
--- a/src/cache/backings/file_common.c
+++ b/src/cache/backings/file_common.c
@@ -1,24 +1,24 @@
static off_t file_backing_get_size_estimate(struct cch_backing *backing)
{
struct cch_backing_file *file = (struct cch_backing_file *)backing;
- aki_mutex_lock(&file->mutex);
+ nn_mutex_lock(&file->mutex);
off_t size = file->size;
- aki_mutex_unlock(&file->mutex);
+ nn_mutex_unlock(&file->mutex);
return size;
}
static bool file_open_internal(struct cch_backing_file *file, str *path, size_t size)
{
- s32 flags = size != 0 ? AKI_FILE_CREATE : 0;
- if (!aki_file_open(&file->file, path, flags)) return false;
- file->filesize = aki_file_get_filesize(&file->file);
+ s32 flags = size != 0 ? NNWT_FILE_CREATE : 0;
+ if (!nn_file_open(&file->file, path, flags)) return false;
+ file->filesize = nn_file_get_filesize(&file->file);
if (!size) {
file->size = file->filesize;
cch_backing_fill_range(&file->backing, 0, file->size);
} else {
file->size = -1;
if (file->filesize < (off_t)size) {
- aki_file_truncate(&file->file, size);
+ nn_file_truncate(&file->file, size);
}
}
return true;
diff --git a/src/cache/backings/file_mapped.c b/src/cache/backings/file_mapped.c
index 22f9ae5..35ab267 100644
--- a/src/cache/backings/file_mapped.c
+++ b/src/cache/backings/file_mapped.c
@@ -6,25 +6,25 @@
static void file_backing_lock(struct cch_backing *backing)
{
struct cch_backing_file *file = (struct cch_backing_file *)backing;
- aki_mutex_lock(&file->mutex);
+ nn_mutex_lock(&file->mutex);
}
static void file_backing_write(struct cch_backing *backing, u8 *buf, off_t index, size_t *size)
{
struct cch_backing_file *file = (struct cch_backing_file *)backing;
- aki_mutex_lock(&file->mutex);
+ nn_mutex_lock(&file->mutex);
if (file->size >= 0 && index + (off_t)*size >= file->size) {
*size = MAX(file->size - index, 0L);
}
al_memcpy(file->u.map + index, buf, *size);
cch_backing_fill_range(&file->backing, index, *size);
- aki_mutex_unlock(&file->mutex);
+ nn_mutex_unlock(&file->mutex);
}
static u8 *file_backing_get_ptr(struct cch_backing *backing, off_t index, size_t *size)
{
struct cch_backing_file *file = (struct cch_backing_file *)backing;
- aki_mutex_lock(&file->mutex);
+ nn_mutex_lock(&file->mutex);
if (file->size >= 0 && index + (off_t)*size >= file->size) {
*size = MAX(file->size - index, 0L);
}
@@ -34,28 +34,28 @@ static u8 *file_backing_get_ptr(struct cch_backing *backing, off_t index, size_t
static void file_backing_unlock(struct cch_backing *backing)
{
struct cch_backing_file *file = (struct cch_backing_file *)backing;
- aki_mutex_unlock(&file->mutex);
+ nn_mutex_unlock(&file->mutex);
}
static void file_backing_resize(struct cch_backing *backing, size_t size)
{
struct cch_backing_file *file = (struct cch_backing_file *)backing;
- aki_mutex_lock(&file->mutex);
+ nn_mutex_lock(&file->mutex);
file->size = size;
if ((off_t)size > file->filesize) {
- aki_file_munmap(&file->file, file->u.map);
- aki_file_truncate(&file->file, size);
- file->u.map = aki_file_mmap(&file->file);
+ nn_file_munmap(&file->file, file->u.map);
+ nn_file_truncate(&file->file, size);
+ file->u.map = nn_file_mmap(&file->file);
file->filesize = size;
}
- aki_mutex_unlock(&file->mutex);
+ nn_mutex_unlock(&file->mutex);
}
static void file_backing_free(struct cch_backing **backing)
{
struct cch_backing_file *file = (struct cch_backing_file *)*backing;
- aki_file_munmap(&file->file, file->u.map);
- aki_file_close(&file->file);
+ nn_file_munmap(&file->file, file->u.map);
+ nn_file_close(&file->file);
al_array_free(file->backing.available);
al_free(file);
*backing = NULL;
@@ -74,10 +74,10 @@ struct cch_backing *cch_backing_file_create(str *path, size_t size)
file->backing.resize = file_backing_resize;
file->backing.free = file_backing_free;
al_array_init(file->backing.available);
- if (!file_open_internal(file, path, size) || !(file->u.map = aki_file_mmap(&file->file))) {
+ if (!file_open_internal(file, path, size) || !(file->u.map = nn_file_mmap(&file->file))) {
al_free(file);
return NULL;
}
- aki_mutex_init(&file->mutex);
+ nn_mutex_init(&file->mutex);
return (struct cch_backing *)file;
}
diff --git a/src/cache/backings/memory.c b/src/cache/backings/memory.c
index 5db2063..aa5c1b4 100644
--- a/src/cache/backings/memory.c
+++ b/src/cache/backings/memory.c
@@ -13,28 +13,28 @@ static void ensure_alloced(struct cch_backing_memory *mem, size_t size)
static void memory_backing_lock(struct cch_backing *backing)
{
struct cch_backing_memory *mem = (struct cch_backing_memory *)backing;
- aki_mutex_lock(&mem->mutex);
+ nn_mutex_lock(&mem->mutex);
}
static void memory_backing_write(struct cch_backing *backing, u8 *buf, off_t index, size_t *size)
{
struct cch_backing_memory *mem = (struct cch_backing_memory *)backing;
- aki_mutex_lock(&mem->mutex);
+ nn_mutex_lock(&mem->mutex);
if (mem->size >= 0 && index + (off_t)*size >= mem->size) {
- *size = MAX(mem->size - index, 0L);
+ *size = MAX(mem->size - index, (off_t)0L);
}
ensure_alloced(mem, index + *size);
al_memcpy(mem->data + index, buf, *size);
cch_backing_fill_range(&mem->backing, index, *size);
- aki_mutex_unlock(&mem->mutex);
+ nn_mutex_unlock(&mem->mutex);
}
static u8 *memory_backing_get_ptr(struct cch_backing *backing, off_t index, size_t *size)
{
struct cch_backing_memory *mem = (struct cch_backing_memory *)backing;
- aki_mutex_lock(&mem->mutex);
+ nn_mutex_lock(&mem->mutex);
if (mem->size >= 0 && index + (off_t)*size >= mem->size) {
- *size = MAX(mem->size - index, 0L);
+ *size = MAX(mem->size - index, (off_t)0L);
}
return (u8 *)(mem->data + index);
}
@@ -42,32 +42,32 @@ static u8 *memory_backing_get_ptr(struct cch_backing *backing, off_t index, size
static void memory_backing_unlock(struct cch_backing *backing)
{
struct cch_backing_memory *mem = (struct cch_backing_memory *)backing;
- aki_mutex_unlock(&mem->mutex);
+ nn_mutex_unlock(&mem->mutex);
}
static off_t memory_backing_get_size_estimate(struct cch_backing *backing)
{
struct cch_backing_memory *mem = (struct cch_backing_memory *)backing;
- aki_mutex_lock(&mem->mutex);
+ nn_mutex_lock(&mem->mutex);
off_t size = mem->size;
- aki_mutex_unlock(&mem->mutex);
+ nn_mutex_unlock(&mem->mutex);
return size;
}
static void memory_backing_resize(struct cch_backing *backing, size_t size)
{
struct cch_backing_memory *mem = (struct cch_backing_memory *)backing;
- aki_mutex_lock(&mem->mutex);
+ nn_mutex_lock(&mem->mutex);
ensure_alloced(mem, size);
mem->size = size;
- aki_mutex_unlock(&mem->mutex);
+ nn_mutex_unlock(&mem->mutex);
}
static void memory_backing_free(struct cch_backing **backing)
{
struct cch_backing_memory *mem = (struct cch_backing_memory *)*backing;
al_free(mem->data);
- aki_mutex_destroy(&mem->mutex);
+ nn_mutex_destroy(&mem->mutex);
al_array_free(mem->backing.available);
al_free(mem);
*backing = NULL;
@@ -87,7 +87,7 @@ struct cch_backing *cch_backing_memory_create(size_t size)
mem->data = al_malloc(size);
mem->alloc = size;
mem->size = -1;
- aki_mutex_init(&mem->mutex);
+ nn_mutex_init(&mem->mutex);
al_array_init(mem->backing.available);
return (struct cch_backing *)mem;
}
diff --git a/src/cache/backings/memory.h b/src/cache/backings/memory.h
index 107ae4b..e290b48 100644
--- a/src/cache/backings/memory.h
+++ b/src/cache/backings/memory.h
@@ -1,7 +1,7 @@
#pragma once
#include <al/lib.h>
-#include <aki/thread.h>
+#include <nnwt/thread.h>
#include "../backing.h"
@@ -10,7 +10,7 @@ struct cch_backing_memory {
u8 *data;
size_t alloc;
off_t size;
- struct aki_mutex mutex;
+ struct nn_mutex mutex;
};
struct cch_backing *cch_backing_memory_create(size_t size);
diff --git a/src/cache/entry.c b/src/cache/entry.c
index 8068397..c7fb8d2 100644
--- a/src/cache/entry.c
+++ b/src/cache/entry.c
@@ -7,12 +7,12 @@ bool cch_entry_get_handle(struct cch_entry *entry, struct cch_handle *handle)
handle->entry = entry;
handle->pointer = 0;
handle->prev_pointer = 0;
- aki_cond_init(&handle->wait.cond);
- aki_mutex_init(&handle->wait.mutex);
+ nn_cond_init(&handle->wait.cond);
+ nn_mutex_init(&handle->wait.mutex);
handle->wait.disabled = false;
- aki_mutex_lock(&entry->mutex);
+ nn_mutex_lock(&entry->mutex);
entry->ref_count++;
- aki_mutex_unlock(&entry->mutex);
+ nn_mutex_unlock(&entry->mutex);
return true;
}
@@ -43,15 +43,15 @@ void cch_entry_return_handle(struct cch_entry *entry, struct cch_handle *handle)
{
handle->entry = NULL;
entry->ref_count--;
- aki_mutex_destroy(&handle->wait.mutex);
- aki_cond_destroy(&handle->wait.cond);
+ nn_mutex_destroy(&handle->wait.mutex);
+ nn_cond_destroy(&handle->wait.cond);
}
void cch_entry_free(struct cch_entry **entry)
{
(*entry)->handler->free(&(*entry)->handler);
(*entry)->backing->free(&(*entry)->backing);
- aki_mutex_destroy(&(*entry)->mutex);
+ nn_mutex_destroy(&(*entry)->mutex);
al_free(*entry);
*entry = NULL;
}
diff --git a/src/cache/entry.h b/src/cache/entry.h
index 3196809..4a20058 100644
--- a/src/cache/entry.h
+++ b/src/cache/entry.h
@@ -19,7 +19,7 @@ struct cch_entry {
struct cch_chapter *chapter;
struct cch_backing *backing;
struct cch_handler *handler;
- struct aki_mutex mutex;
+ struct nn_mutex mutex;
};
bool cch_entry_get_handle(struct cch_entry *entry, struct cch_handle *handle);
diff --git a/src/cache/handle.h b/src/cache/handle.h
index ae936f3..fc84109 100644
--- a/src/cache/handle.h
+++ b/src/cache/handle.h
@@ -1,7 +1,7 @@
#pragma once
#include <al/types.h>
-#include <aki/thread.h>
+#include <nnwt/thread.h>
#include "wait.h"
diff --git a/src/cache/handler.h b/src/cache/handler.h
index 9dd1896..b4c6975 100644
--- a/src/cache/handler.h
+++ b/src/cache/handler.h
@@ -3,7 +3,7 @@
#include <al/types.h>
#include <al/array.h>
#include <al/str.h>
-#include <aki/thread.h>
+#include <nnwt/thread.h>
#include "handle.h"
@@ -15,6 +15,6 @@ struct cch_handler {
struct cch_entry *entry;
str liana;
bool disabled;
- struct aki_mutex mutex;
+ struct nn_mutex mutex;
array(struct cch_handler_wait *) waits;
};
diff --git a/src/cache/handlers/cdio.c b/src/cache/handlers/cdio.c
index 23f87b6..b10bbf1 100644
--- a/src/cache/handlers/cdio.c
+++ b/src/cache/handlers/cdio.c
@@ -31,7 +31,7 @@ static bool handler_cdio_can_seek(struct cch_handler *handler)
return true;
}
-static aki_thread_result AKI_THREADCALL cd_read_thread(void *userdata)
+static nn_thread_result NNWT_THREADCALL cd_read_thread(void *userdata)
{
struct cch_handler_cdio *cdio = (struct cch_handler_cdio *)userdata;
while (1) {
@@ -41,7 +41,7 @@ static aki_thread_result AKI_THREADCALL cd_read_thread(void *userdata)
}
// cdio_read() here can block for a very long time so we buffer each read
// before writing it to the backing.
- long ret = cdio_cddap_read(cdio->drive, aki_buffer_get_ptr(&cdio->buffer, 0), cdio->sector, SECTORS_PER_STEP);
+ long ret = cdio_cddap_read(cdio->drive, nn_buffer_get_ptr(&cdio->buffer, 0), cdio->sector, SECTORS_PER_STEP);
cdio_log_messages(cdio);
al_assert(ret <= SECTORS_PER_STEP);
off_t pointer = cdio->sector * CDIO_CD_FRAMESIZE_RAW;
@@ -53,7 +53,7 @@ static aki_thread_result AKI_THREADCALL cd_read_thread(void *userdata)
break;
}
if (ret == SECTORS_PER_STEP) {
- al_memcpy(ptr, aki_buffer_get_ptr(&cdio->buffer, 0), BYTES_PER_STEP);
+ al_memcpy(ptr, nn_buffer_get_ptr(&cdio->buffer, 0), BYTES_PER_STEP);
} else if (ret == -10) {
al_log_error("cdio", "I/O error, skipping sector.");
al_memset(ptr, 0, BYTES_PER_STEP);
@@ -86,12 +86,12 @@ static void handler_cdio_maybe_spawn_worker(struct cch_handler *handler, size_t
if (cdio->start == (lsn_t)index) return;
if (al_atomic_load(s32)(&cdio->running, AL_ATOMIC_ACQUIRE)) {
al_atomic_store(s32)(&cdio->running, 0, AL_ATOMIC_RELEASE);
- aki_thread_join(&cdio->thread);
+ nn_thread_join(&cdio->thread);
}
cdio->start = index;
cdio->sector = cdio->start;
al_atomic_store(s32)(&cdio->running, 1, AL_ATOMIC_RELEASE);
- aki_thread_create(&cdio->thread, cd_read_thread, cdio);
+ nn_thread_create(&cdio->thread, cd_read_thread, cdio);
}
static bool handler_cdio_wait_for_range(struct cch_handler *handler, struct cch_handler_wait *wait)
@@ -106,7 +106,7 @@ static void handler_cdio_free(struct cch_handler **handler)
cch_threaded_waits_disable_all(&cdio->handler);
if (al_atomic_load(s32)(&cdio->running, AL_ATOMIC_RELAXED)) {
al_atomic_store(s32)(&cdio->running, 0, AL_ATOMIC_RELAXED);
- aki_thread_join(&cdio->thread);
+ nn_thread_join(&cdio->thread);
}
if (cdio->drive) {
cdio_log_messages(cdio);
@@ -189,7 +189,7 @@ struct cch_entry *cch_handler_cdio_create(void)
entry->ref_count = 0;
entry->unknown_size = false;
entry->hash = 0;
- aki_mutex_init(&entry->mutex);
+ nn_mutex_init(&entry->mutex);
entry->handler->can_seek = handler_cdio_can_seek;
entry->handler->maybe_spawn_worker = handler_cdio_maybe_spawn_worker;
entry->handler->wait_for_range = handler_cdio_wait_for_range;
@@ -198,9 +198,9 @@ struct cch_entry *cch_handler_cdio_create(void)
al_str_from(&entry->handler->liana, "cdio");
if (!open_cd_drive(cdio)) return NULL;
al_atomic_store(s32)(&cdio->running, 0, AL_ATOMIC_RELAXED);
- aki_buffer_init(&cdio->buffer);
- aki_buffer_ensure_space(&cdio->buffer, BYTES_PER_STEP);
- aki_buffer_set_size(&cdio->buffer, BYTES_PER_STEP);
+ nn_buffer_init(&cdio->buffer);
+ nn_buffer_ensure_space(&cdio->buffer, BYTES_PER_STEP);
+ nn_buffer_set_size(&cdio->buffer, BYTES_PER_STEP);
cch_threaded_waits_init(&cdio->handler);
return entry;
}
diff --git a/src/cache/handlers/cdio.h b/src/cache/handlers/cdio.h
index 953c988..3a3966a 100644
--- a/src/cache/handlers/cdio.h
+++ b/src/cache/handlers/cdio.h
@@ -1,5 +1,5 @@
#include <al/atomic.h>
-#include <aki/common.h>
+#include <nnwt/common.h>
#include <cdio/paranoia/cdda.h>
#include <cdio/cd_types.h>
@@ -13,9 +13,9 @@ struct cch_handler_cdio {
lsn_t start;
lsn_t end;
lsn_t sector;
+ struct nn_buffer buffer;
atomic(s32) running;
- struct aki_thread thread;
- struct aki_buffer buffer;
+ struct nn_thread thread;
};
struct cch_entry *cch_handler_cdio_create(void);
diff --git a/src/cache/handlers/file.c b/src/cache/handlers/file.c
index 03e2814..c09aac0 100644
--- a/src/cache/handlers/file.c
+++ b/src/cache/handlers/file.c
@@ -42,7 +42,7 @@ struct cch_entry *cch_handler_file_create(str *path)
entry->ref_count = 0;
entry->unknown_size = false;
entry->hash = 0;
- aki_mutex_init(&entry->mutex);
+ nn_mutex_init(&entry->mutex);
entry->handler->can_seek = handler_file_can_seek;
entry->handler->maybe_spawn_worker = handler_file_maybe_spawn_worker;
entry->handler->wait_for_range = handler_file_wait_for_range;
diff --git a/src/cache/handlers/http.c b/src/cache/handlers/http.c
index 71ae186..308633e 100644
--- a/src/cache/handlers/http.c
+++ b/src/cache/handlers/http.c
@@ -21,39 +21,37 @@ static size_t http_callback(void *userdata, u8 op, u8 *buf, s64 int0)
struct cch_handler_http *http = (struct cch_handler_http *)userdata;
size_t ret = (size_t)int0;
switch (op) {
- case AKI_HTTP_FINISHED: {
- al_log_debug("cache_handler_http", "Transfer finished.");
- break;
- }
- case AKI_HTTP_ERROR: {
- cch_threaded_waits_disable_all(&http->handler);
+ case NNWT_HTTP_READ:
+ al_assert_and_return(0);
+ case NNWT_HTTP_WRITE: {
+ // If we got data before a Content-Length, assume the size is unknown.
+ if (cch_entry_get_size(http->handler.entry) < 0) {
+ cch_entry_set_size(http->handler.entry, 0);
+ }
+ http->backing->write(http->backing, buf, http->pointer, &ret);
+ http->pointer += ret;
+ cch_threaded_waits_evaluate(&http->handler, http->backing);
break;
}
- case AKI_HTTP_RESPONSE_CODE: {
+ case NNWT_HTTP_RESPONSE_CODE:
al_log_debug("cache_handler_http", "HTTP %ld.", int0);
break;
- }
- case AKI_HTTP_REDIRECT: {
- al_log_debug("cache_handler_http", "Redirect.");
- break;
- }
- case AKI_HTTP_CONTENT_LENGTH: {
+ case NNWT_HTTP_CONTENT_LENGTH: {
off_t content_length = (off_t)int0;
al_log_debug("cache_handler_http", "Content-Length: %lld.", content_length);
cch_entry_set_size(http->handler.entry, content_length);
cch_threaded_waits_signal_any(&http->handler);
break;
}
- case AKI_HTTP_WRITE: {
- // If we got data before a Content-Length, assume the size is unknown.
- if (cch_entry_get_size(http->handler.entry) < 0) {
- cch_entry_set_size(http->handler.entry, 0);
- }
- http->backing->write(http->backing, buf, http->pointer, &ret);
- http->pointer += ret;
- cch_threaded_waits_evaluate(&http->handler, http->backing);
+ case NNWT_HTTP_REDIRECT:
+ al_log_debug("cache_handler_http", "Redirect %ld.", int0);
+ break;
+ case NNWT_HTTP_FINISHED:
+ al_log_debug("cache_handler_http", "Transfer finished.");
+ break;
+ case NNWT_HTTP_ERROR:
+ cch_threaded_waits_disable_all(&http->handler);
break;
- }
default:
break;
}
@@ -64,12 +62,12 @@ static void handler_http_maybe_spawn_worker(struct cch_handler *handler, size_t
{
struct cch_handler_http *http = (struct cch_handler_http *)handler;
(void)index;
- al_array_push(http->requests, (struct aki_http){ 0 });
- struct aki_http *request = &al_array_last(http->requests);
- aki_http_init(request);
- aki_http_set_url(request, &http->url);
- aki_http_set_user_agent(request, USER_AGENT);
- aki_http_request_stream(request, AKI_HTTP_GET, http->loop, http_callback, http);
+ al_array_push(http->requests, (struct nn_http){ 0 });
+ struct nn_http *request = &al_array_last(http->requests);
+ nn_http_init(request);
+ nn_http_set_url(request, &http->url);
+ nn_http_set_user_agent(request, USER_AGENT);
+ nn_http_request_stream(request, NNWT_HTTP_GET, http->loop, http_callback, http);
}
static bool handler_http_wait_for_range(struct cch_handler *handler, struct cch_handler_wait *wait)
@@ -82,9 +80,9 @@ static void handler_http_free(struct cch_handler **handler)
{
struct cch_handler_http *http = (struct cch_handler_http *)*handler;
cch_threaded_waits_disable_all(&http->handler);
- struct aki_http *request;
+ struct nn_http *request;
al_array_foreach_ptr(http->requests, i, request) {
- aki_http_close(request);
+ nn_http_close(request);
}
cch_threaded_waits_close(&http->handler);
al_array_free(http->requests);
@@ -94,7 +92,7 @@ static void handler_http_free(struct cch_handler **handler)
*handler = NULL;
}
-struct cch_entry *cch_handler_http_create(str *url, struct aki_event_loop *loop)
+struct cch_entry *cch_handler_http_create(str *url, struct nn_event_loop *loop)
{
struct cch_backing *backing = cch_backing_memory_create(1024 * 128);
if (!backing) return NULL;
@@ -106,7 +104,7 @@ struct cch_entry *cch_handler_http_create(str *url, struct aki_event_loop *loop)
entry->ref_count = 0;
entry->unknown_size = false;
entry->hash = 0;
- aki_mutex_init(&entry->mutex);
+ nn_mutex_init(&entry->mutex);
entry->handler->can_seek = handler_http_can_seek;
entry->handler->maybe_spawn_worker = handler_http_maybe_spawn_worker;
entry->handler->wait_for_range = handler_http_wait_for_range;
diff --git a/src/cache/handlers/http.h b/src/cache/handlers/http.h
index 5f9df86..ef47173 100644
--- a/src/cache/handlers/http.h
+++ b/src/cache/handlers/http.h
@@ -1,8 +1,8 @@
#pragma once
-#include <aki/http.h>
-#include <aki/thread.h>
-#include <aki/signal.h>
+#include <nnwt/http.h>
+#include <nnwt/thread.h>
+#include <nnwt/signal.h>
#include "../handler.h"
#include "../entry.h"
@@ -12,8 +12,8 @@ struct cch_handler_http {
struct cch_backing *backing;
str url;
off_t pointer;
- array(struct aki_http) requests;
- struct aki_event_loop *loop;
+ array(struct nn_http) requests;
+ struct nn_event_loop *loop;
};
-struct cch_entry *cch_handler_http_create(str *url, struct aki_event_loop *loop);
+struct cch_entry *cch_handler_http_create(str *url, struct nn_event_loop *loop);
diff --git a/src/cache/meson.build b/src/cache/meson.build
index 5fb47ae..5b70c3c 100644
--- a/src/cache/meson.build
+++ b/src/cache/meson.build
@@ -6,6 +6,7 @@ cache_src = [
'backings/memory.c'
]
cache_deps = []
+cache_args = []
cache_have_cdio = false
libcdio_paranoia = dependency('libcdio_paranoia', required: false, allow_fallback: true)
@@ -13,6 +14,7 @@ libcdio_cdda = dependency('libcdio_cdda', required: false, allow_fallback: true)
if libcdio_paranoia.found() and libcdio_cdda.found()
cache_src += ['handlers/cdio.c']
cache_deps += [libcdio_paranoia, libcdio_cdda]
+ cache_args += ['-DCACHE_HAVE_CDIO']
cache_have_cdio = true
endif
@@ -22,14 +24,15 @@ endif
#if libdvdcss.found() and libdvdread.found() and libdvdnav.found()
#endif
-if akiyo_has_mmap
+if naunet_has_mmap
cache_src += ['backings/file_mapped.c']
else
cache_src += ['backings/file.c']
endif
-if akiyo_has_curl
+if naunet_has_curl
cache_src += ['handlers/http.c']
endif
-cache = declare_dependency(sources: cache_src, dependencies: cache_deps)
+cache = declare_dependency(sources: cache_src, dependencies: cache_deps,
+ compile_args: cache_args)
diff --git a/src/cache/threaded_waits.c b/src/cache/threaded_waits.c
index 10f08f0..3bf67eb 100644
--- a/src/cache/threaded_waits.c
+++ b/src/cache/threaded_waits.c
@@ -4,7 +4,7 @@
void cch_threaded_waits_init(struct cch_handler *handler)
{
handler->disabled = false;
- aki_mutex_init(&handler->mutex);
+ nn_mutex_init(&handler->mutex);
al_array_init(handler->waits);
}
@@ -22,104 +22,98 @@ static bool wait_range_satisfied(struct cch_backing *backing, struct cch_handler
bool cch_threaded_wait_for_range(struct cch_handler *handler, struct cch_backing *backing, struct cch_handler_wait *wait)
{
- aki_mutex_lock(&handler->mutex);
+ nn_mutex_lock(&handler->mutex);
bool canceled = handler->disabled;
off_t size = cch_entry_get_size(handler->entry);
backing->lock(backing);
bool satisfied = size >= 0 && wait_range_satisfied(backing, wait);
backing->unlock(backing);
if (!canceled && !satisfied) {
- aki_mutex_lock(&wait->mutex);
+ nn_mutex_lock(&wait->mutex);
if (!wait->disabled) {
al_array_push(handler->waits, wait);
- aki_mutex_unlock(&handler->mutex);
- aki_cond_wait(&wait->cond, &wait->mutex);
+ nn_mutex_unlock(&handler->mutex);
+ nn_cond_wait(&wait->cond, &wait->mutex);
} else {
- aki_mutex_unlock(&wait->mutex);
- aki_mutex_unlock(&handler->mutex);
+ nn_mutex_unlock(&wait->mutex);
+ nn_mutex_unlock(&handler->mutex);
return false;
}
- aki_mutex_unlock(&wait->mutex);
- aki_mutex_lock(&handler->mutex);
+ nn_mutex_unlock(&wait->mutex);
+ nn_mutex_lock(&handler->mutex);
if (wait->disabled) {
- struct cch_handler_wait *rwait;
- al_array_foreach(handler->waits, i, rwait) {
- if (rwait == wait) {
- al_array_remove_at(handler->waits, i);
- break;
- }
- }
+ al_array_remove(handler->waits, wait);
canceled = true;
}
}
- aki_mutex_unlock(&handler->mutex);
+ nn_mutex_unlock(&handler->mutex);
return !canceled;
}
void cch_threaded_waits_signal_any(struct cch_handler *handler)
{
- aki_mutex_lock(&handler->mutex);
+ nn_mutex_lock(&handler->mutex);
struct cch_handler_wait *wait;
al_array_foreach_rev(handler->waits, i, wait) {
if (wait->end < 0) {
al_array_remove_at(handler->waits, i);
- aki_mutex_lock(&wait->mutex);
- aki_cond_signal(&wait->cond);
- aki_mutex_unlock(&wait->mutex);
+ nn_mutex_lock(&wait->mutex);
+ nn_cond_signal(&wait->cond);
+ nn_mutex_unlock(&wait->mutex);
}
}
- aki_mutex_unlock(&handler->mutex);
+ nn_mutex_unlock(&handler->mutex);
}
void cch_threaded_wait_disable(struct cch_handler_wait *wait)
{
- aki_mutex_lock(&wait->mutex);
+ nn_mutex_lock(&wait->mutex);
wait->disabled = true;
// cond_is_waiting() could be false if the handler is disabled.
- if (aki_cond_is_waiting(&wait->cond)) {
- aki_cond_signal(&wait->cond);
+ if (nn_cond_is_waiting(&wait->cond)) {
+ nn_cond_signal(&wait->cond);
}
- aki_mutex_unlock(&wait->mutex);
+ nn_mutex_unlock(&wait->mutex);
}
void cch_threaded_waits_disable_all(struct cch_handler *handler)
{
- aki_mutex_lock(&handler->mutex);
+ nn_mutex_lock(&handler->mutex);
if (handler->disabled) {
- aki_mutex_unlock(&handler->mutex);
+ nn_mutex_unlock(&handler->mutex);
return;
}
// Disallow any further waits.
handler->disabled = true;
struct cch_handler_wait *wait;
al_array_foreach(handler->waits, i, wait) {
- aki_mutex_lock(&wait->mutex);
+ nn_mutex_lock(&wait->mutex);
wait->disabled = true;
- aki_cond_signal(&wait->cond);
- aki_mutex_unlock(&wait->mutex);
+ nn_cond_signal(&wait->cond);
+ nn_mutex_unlock(&wait->mutex);
}
- aki_mutex_unlock(&handler->mutex);
+ nn_mutex_unlock(&handler->mutex);
}
void cch_threaded_waits_evaluate(struct cch_handler *handler, struct cch_backing *backing)
{
- aki_mutex_lock(&handler->mutex);
+ nn_mutex_lock(&handler->mutex);
backing->lock(backing);
struct cch_handler_wait *wait;
al_array_foreach_rev(handler->waits, i, wait) {
- aki_mutex_lock(&wait->mutex);
+ nn_mutex_lock(&wait->mutex);
if (wait_range_satisfied(backing, wait)) {
- aki_cond_signal(&wait->cond);
+ nn_cond_signal(&wait->cond);
al_array_remove_at(handler->waits, i);
}
- aki_mutex_unlock(&wait->mutex);
+ nn_mutex_unlock(&wait->mutex);
}
backing->unlock(backing);
- aki_mutex_unlock(&handler->mutex);
+ nn_mutex_unlock(&handler->mutex);
}
void cch_threaded_waits_close(struct cch_handler *handler)
{
- aki_mutex_destroy(&handler->mutex);
+ nn_mutex_destroy(&handler->mutex);
al_array_free(handler->waits);
}
diff --git a/src/cache/wait.h b/src/cache/wait.h
index 8654362..4c9b228 100644
--- a/src/cache/wait.h
+++ b/src/cache/wait.h
@@ -1,10 +1,10 @@
#pragma once
-#include <aki/thread.h>
+#include <nnwt/thread.h>
struct cch_handler_wait {
off_t start, end;
- struct aki_cond cond;
- struct aki_mutex mutex;
+ struct nn_cond cond;
+ struct nn_mutex mutex;
bool disabled;
};