Fix tests?

This commit is contained in:
2026-06-02 07:35:28 -05:00
parent 88903fee94
commit 3770ae1645
3 changed files with 23 additions and 6 deletions
+17 -6
View File
@@ -82,17 +82,23 @@ errorret_t assetRequireLoaded(assetentry_t *entry) {
assertNotNull(entry, "Entry cannot be NULL."); assertNotNull(entry, "Entry cannot be NULL.");
assertTrue(entry->type != ASSET_LOADER_TYPE_NULL, "Invalid loader type."); assertTrue(entry->type != ASSET_LOADER_TYPE_NULL, "Invalid loader type.");
// Already loaded?
if(entry->state == ASSET_ENTRY_STATE_LOADED) { if(entry->state == ASSET_ENTRY_STATE_LOADED) {
errorOk(); errorOk();
} }
// Not loaded, just spin the wheel // Lock to prevent the reaper from collecting the entry mid-spin.
assetEntryLock(entry);
while(entry->state != ASSET_ENTRY_STATE_LOADED) { while(entry->state != ASSET_ENTRY_STATE_LOADED) {
usleep(1000); usleep(1000);
errorChain(assetUpdate()); errorret_t ret = assetUpdate();
if(errorIsNotOk(ret)) {
assetEntryUnlock(entry);
errorChain(ret);
}
} }
assetEntryUnlock(entry);
errorOk(); errorOk();
} }
@@ -246,9 +252,9 @@ errorret_t assetUpdate(void) {
} while(loading < ASSET.loading + ASSET_LOADING_COUNT_MAX); } while(loading < ASSET.loading + ASSET_LOADING_COUNT_MAX);
// Reap entries that have no external locks (refs.count == 1 means only the // Reap entries that have no external locks (refs.count == 0) AND have been
// system hold remains). Only safe to reap LOADED and NOT_STARTED states — // explicitly locked at least once. Entries that were never locked are left
// mid-load entries are left for the next cycle. // alone — raw-pointer callers hold no ref but should not lose the entry.
entry = ASSET.entries; entry = ASSET.entries;
do { do {
if(entry->state != ASSET_ENTRY_STATE_LOADED) { if(entry->state != ASSET_ENTRY_STATE_LOADED) {
@@ -261,6 +267,11 @@ errorret_t assetUpdate(void) {
continue; continue;
} }
if(!entry->wasLocked) {
entry++;
continue;
}
if(entry->refs.count > 0) { if(entry->refs.count > 0) {
entry++; entry++;
continue; continue;
+1
View File
@@ -33,6 +33,7 @@ void assetEntryInit(
void assetEntryLock(assetentry_t *entry) { void assetEntryLock(assetentry_t *entry) {
assertNotNull(entry, "Entry cannot be NULL"); assertNotNull(entry, "Entry cannot be NULL");
assertTrue(entry->type != ASSET_LOADER_TYPE_NULL, "Invalid loader type."); assertTrue(entry->type != ASSET_LOADER_TYPE_NULL, "Invalid loader type.");
entry->wasLocked = true;
refLock(&entry->refs); refLock(&entry->refs);
} }
+5
View File
@@ -30,6 +30,11 @@ typedef struct assetentry_s {
assetentrystate_t state; assetentrystate_t state;
// What is referencing this asset entry. // What is referencing this asset entry.
ref_t refs; ref_t refs;
// True once assetEntryLock has been called at least once. The reaper only
// collects entries that have been explicitly locked (and later unlocked to
// zero). Entries that nobody has ever locked are left alone so raw-pointer
// callers (tests, requireLoaded before locking) are not surprised.
bool_t wasLocked;
// Data that will be passed to the loader about how it should load. // Data that will be passed to the loader about how it should load.
assetloaderinput_t *input; assetloaderinput_t *input;
} assetentry_t; } assetentry_t;