void NativeDelegate::assertMainThread() { lmAssert(smMainThreadID != scmBadThreadID, "Tried to touch a NativeDelegate before the main thread was marked. " "Probably need to add a markMainThread call?"); lmAssert(platform_getCurrentThreadId() == smMainThreadID, "Trying to fire a NativeDelegate from thread %x that is not the main " "thread %x. This will result in memory corruption and race conditions!", platform_getCurrentThreadId(), smMainThreadID); }
NativeDelegateCallNote *NativeDelegate::prepCallbackNote() const { lmLogDebug(gNativeDelegateGroup, "Considering async callback %x", this); // Are noting currently? Just work with that. if(_activeNote) { lmLogDebug(gNativeDelegateGroup, " OUT due to activeNote already present"); return _activeNote; } // See if we should try to go async. if(_allowAsync == false) { lmLogDebug(gNativeDelegateGroup, " OUT due to async being disallowed"); return NULL; } if(smMainThreadID == platform_getCurrentThreadId()) return NULL; // Only do this for async delegates off main thread. lmLogDebug(gNativeDelegateGroup, "Prepping async callback!"); _activeNote = lmNew(NULL) NativeDelegateCallNote(this); return _activeNote; }
void loom_asset_flush(const char *name) { // Currently we only want to do this on the main thread so piggy back on the // native delegate sanity check to bail if on secondary thread. if(platform_getCurrentThreadId() != LS::NativeDelegate::smMainThreadID && LS::NativeDelegate::smMainThreadID != 0xBAADF00D) return; loom_mutex_lock(gAssetLock); // Delete it + unload it. loom_asset_t *asset = loom_asset_getAssetByName(name, 0); if(!asset || asset->isSupplied) { loom_mutex_unlock(gAssetLock); return; } lmLogDebug(gAssetLogGroup, "Flushing '%s'", name); if (asset->blob) { asset->blob->decRef(); asset->blob = NULL; } asset->state = loom_asset_t::Unloaded; // Fire subscribers. if(!gShuttingDown) loom_asset_notifySubscribers(asset->name.c_str()); loom_mutex_unlock(gAssetLock); }
void loom_asset_pump() { // Currently we only want to do this on the main thread so piggy back on the // native delegate sanity check to bail if on secondary thread. if(platform_getCurrentThreadId() != LS::NativeDelegate::smMainThreadID && LS::NativeDelegate::smMainThreadID != 0xBAADF00D) return; loom_mutex_lock(gAssetLock); // Talk to the asset server. loom_asset_serviceServer(); // For now just blast all the data from each file into the asset. while(gAssetLoadQueue.size()) { loom_asset_t *asset = gAssetLoadQueue.front(); // Figure out the type from the path. utString path = asset->name; int type = loom_asset_recognizeAssetTypeFromPath(path); if(type == 0) { lmLog(gAssetLogGroup, "Could not infer type of resource '%s', skipping it...", path.c_str()); asset->state = loom_asset_t::Unloaded; gAssetLoadQueue.erase((UTsize)0, true); continue; } // Open the file. void *ptr; long size; if(!platform_mapFile(asset->name.c_str(), &ptr, &size)) { lmAssert(false, "Could not open file '%s'.", asset->name.c_str()); } // Deserialize it. LoomAssetCleanupCallback dtor = NULL; void *assetBits = loom_asset_deserializeAsset(path, type, size, ptr, &dtor); // Close the file. platform_unmapFile(ptr); // Instate the asset. asset->instate(type, assetBits, dtor); // Done! Update queue. gAssetLoadQueue.erase((UTsize)0, true); } loom_mutex_unlock(gAssetLock); }
void NativeDelegate::markMainThread() { smMainThreadID = platform_getCurrentThreadId(); }