[FEATURE] Add NAM_SINGLE_THREADED option with a threading shim#307
Open
elcamino wants to merge 1 commit into
Open
[FEATURE] Add NAM_SINGLE_THREADED option with a threading shim#307elcamino wants to merge 1 commit into
elcamino wants to merge 1 commit into
Conversation
Route the engine's std::mutex/std::lock_guard/thread_local uses through a new NAM/threading.h. By default the shim aliases the std primitives and nothing changes. With NAM_SINGLE_THREADED defined, locking collapses to no-ops and thread_local to a plain static, for bare-metal targets whose C library has no thread support (newlib without gthreads provides no std::mutex, and thread_local needs a TLS runtime such as __aeabi_read_tp that bare metal lacks). std::atomic is untouched; the embedder guarantees single-threaded use or provides its own external synchronization around model loading and slim switching.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Problem
Since the slimmable-container and version-registry work (#256, #260, #267, #285), the core no longer compiles for bare-metal targets (Arm Cortex-M, newlib). Two independent breakages:
std::mutex(member ofContainerModel, static inget_dsp.cpp) does not exist on newlib without gthreads; libstdc++ only defines it when_GLIBCXX_HAS_GTHREADSis set. Arm GNU Toolchain 15.2:thread_local bool gPrewarmOnResetDefault(dsp.cpp) emits a reference to the TLS runtime, which bare metal does not provide:Before those changes the core built fine on these targets, so embedded users are effectively pinned to pre-0.7.x cores and locked out of the SlimmableContainer/A2 features.
Change
A new
NAM/threading.hroutes the three primitives throughnam::Mutex,nam::LockGuard, andNAM_THREAD_LOCAL. By default these aliasstd::mutex,std::lock_guard, andthread_local— zero change for every existing build. WithNAM_SINGLE_THREADEDdefined, locking collapses to no-ops andNAM_THREAD_LOCALto a plain static: on a single-threaded MCU there is nothing to synchronize, and the embedder takes responsibility for external synchronization if it does run threads.std::atomicis deliberately untouched (newlib supports it, and the lock-free container index should stay atomic).Validation
run_testsgreen (same matrix as CI)-DNAM_SINGLE_THREADEDon desktop: compiles andrun_testsgreen (the shim is semantically neutral in a single-threaded process)