Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[TextServer] Improve text server interlocking. #88241

Draft
wants to merge 1 commit into
base: master
Choose a base branch
from

Conversation

bruvzg
Copy link
Member

@bruvzg bruvzg commented Feb 12, 2024

Fixes #87990, supersede #72646

  • Makes internal TextServer resources ref-counted (since acquired object can be in use when free is called for other thread).
  • Instead of locking the whole TextServer (via _THREAD_SAFE_CLASS_ mutex), only lock RID operation (creation, deletion, and reference acquisition).
  • Individual internal objects already have own mutexes.

@bruvzg
Copy link
Member Author

bruvzg commented Feb 12, 2024

  • Makes internal TextServer resources ref-counted (since acquired object can be in use when free is called for other thread).
  • Instead of locking the whole TextServer (via THREAD_SAFE_CLASS mutex), only lock RID operation (creation, deletion, and reference acquisition).

It's probably worth moving this part to the subclass of RIDOwner, to avoid extra mutex and rely on existing RIDOwner spinlock for reference increments/decrements. Will try it. a bit later.

Copy link
Member

@AThousandShips AThousandShips left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Same on the advanced side

@@ -463,16 +464,33 @@ class TextServerFallback : public TextServerExtension {
mutable RID_PtrOwner<FontFallbackLinkedVariation> font_var_owner;
mutable RID_PtrOwner<FontFallback> font_owner;
mutable RID_PtrOwner<ShapedTextDataFallback> shaped_owner;
mutable Mutex rid_lock;
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
mutable Mutex rid_lock;
mutable Mutex rid_mutex;

Descriptive name IMO

rid_lock.lock();
Ref<ShapedTextDataFallback> ret = Ref<ShapedTextDataFallback>(shaped_owner.get_or_null(p_rid));
rid_lock.unlock();
return ret;
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'd use MutexLock for all these, simpler and safer

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.

Lock-order-inversion detected by ThreadSanitizer in TextServerAdvanced
3 participants