[RNE Rewrite] Extract shared host-object try-lock helper into core - #1331
Open
msluszniak wants to merge 1 commit into
Open
[RNE Rewrite] Extract shared host-object try-lock helper into core#1331msluszniak wants to merge 1 commit into
msluszniak wants to merge 1 commit into
Conversation
Deduplicate the try-lock + liveness-check boilerplate repeated across TokenizerHostObject (5 sites), ModelHostObject (3 sites) and the tensor helpers into a single templated core::tryLock, parameterized over the lock kind (unique/shared) and a liveness predicate. Also document why TokenizerHostObject keeps an exclusive std::mutex despite its ops being const: the vendored Pcre2Regex shares match data across const find_all() calls, so concurrent encodes would race (see #1330).
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.
Description
Resolves the locking + boilerplate items of #1316. Extracts the try-lock + liveness-check block that was duplicated across
TokenizerHostObject(5 sites),ModelHostObject(3 sites) and the tensor helpers into a single templatedcore::tryLockhelper (cpp/core/host_object_lock.h), parameterized over the lock kind (std::unique_lock/std::shared_lock) and a liveness predicate. Error messages are preserved verbatim.On the mutex question from #1316:
TokenizerHostObjectintentionally keeps an exclusivestd::mutexrather than moving tostd::shared_mutex. Although every tokenizer op isconst,constis not thread-safe here — HF tokenizers encode via the PCRE2 fallback, and the vendoredPcre2Regexshares a singlepcre2_match_datamember acrossconst find_all()calls, so concurrent encodes on one tokenizer would race. This is documented intokenizer.hwith aTODOpointing at follow-up #1330 (switch toshared_mutexonce the vendoredtokenizerslib includes the upstream per-call fix).Introduces a breaking change?
Type of change
Tested on
Testing instructions
Pure refactor with no behavior change: the extracted helper reproduces the exact same lock discipline and error strings as the inlined code. Verified the changed translation units compile (
clang++ -std=c++20 -fsyntax-only) and passclang-format.Screenshots
Related issues
Resolves the locking/deduplication parts of #1316. Follow-up: #1330.
Checklist
Additional notes
host_object_lock.his a header-only template, so no CMake change is needed (sources are globbed and it is included where used).