Skip to content

[RNE Rewrite] Extract tokenizer try-lock helper - #1331

Merged
msluszniak merged 2 commits into
rne-rewritefrom
@ms/tokenizer-lock-dedup
Jul 29, 2026
Merged

[RNE Rewrite] Extract tokenizer try-lock helper#1331
msluszniak merged 2 commits into
rne-rewritefrom
@ms/tokenizer-lock-dedup

Conversation

@msluszniak

@msluszniak msluszniak commented Jul 27, 2026

Copy link
Copy Markdown
Member

Description

Resolves the locking + boilerplate items of #1316. Extracts the try-lock + liveness-check block that was duplicated across the five TokenizerHostObject ops into a single class-scoped tryLockUnique member, so callsites read self->tryLockUnique(rt, ctx) — no lambdas or template parameters. Error messages are preserved verbatim. The helper is scoped to the tokenizer rather than shared across host objects, to keep callsites simple and avoid coupling unrelated types.

TokenizerHostObject keeps its exclusive std::mutex.

Introduces a breaking change?

  • Yes
  • No

Type of change

  • Bug fix (change which fixes an issue)
  • New feature (change which adds functionality)
  • Documentation update (improves or adds clarity to existing documentation)
  • Other (chores, tests, code style improvements etc.)

Tested on

  • iOS
  • Android

Testing instructions

Pure refactor with no behavior change: the extracted helper reproduces the exact same lock discipline and error strings as the inlined code.

Screenshots

Related issues

Resolves the locking/deduplication parts of #1316.

Checklist

  • I have performed a self-review of my code
  • I have commented my code, particularly in hard-to-understand areas
  • I have updated the documentation accordingly
  • My changes generate no new warnings

Additional notes

Comment thread packages/react-native-executorch/cpp/core/host_object_lock.h Outdated
Comment thread packages/react-native-executorch/cpp/core/model.cpp
Comment thread packages/react-native-executorch/cpp/extensions/nlp/tokenizer.h Outdated
Deduplicate the try-lock + liveness-check boilerplate repeated across the
five TokenizerHostObject ops into a class-scoped tryLockUnique member, so
callsites read self->tryLockUnique(rt, ctx) without lambdas or template
parameters. Scoped to the tokenizer rather than shared across host objects
to keep ergonomics simple and avoid coupling unrelated types.
@msluszniak
msluszniak force-pushed the @ms/tokenizer-lock-dedup branch from 4c603f9 to f61becb Compare July 29, 2026 13:14
@msluszniak msluszniak changed the title [RNE Rewrite] Extract shared host-object try-lock helper into core [RNE Rewrite] Extract tokenizer try-lock helper Jul 29, 2026
Comment thread packages/react-native-executorch/cpp/extensions/nlp/tokenizer.h Outdated
@msluszniak
msluszniak merged commit 495a87a into rne-rewrite Jul 29, 2026
3 checks passed
@msluszniak
msluszniak deleted the @ms/tokenizer-lock-dedup branch July 29, 2026 14:16
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

[RNE Rewrite] Clean up the tokenizer host object: locking, error unwrapping and native default arg

2 participants