| Summary: | BidiContext caching is not thread-safe | ||||||||
|---|---|---|---|---|---|---|---|---|---|
| Product: | WebKit | Reporter: | Chris Lord <clord> | ||||||
| Component: | WebCore Misc. | Assignee: | Chris Lord <clord> | ||||||
| Status: | RESOLVED FIXED | ||||||||
| Severity: | Normal | CC: | darin, webkit-bug-importer | ||||||
| Priority: | P2 | Keywords: | InRadar | ||||||
| Version: | WebKit Nightly Build | ||||||||
| Hardware: | Unspecified | ||||||||
| OS: | Unspecified | ||||||||
| Bug Depends on: | |||||||||
| Bug Blocks: | 183720, 186759 | ||||||||
| Attachments: |
|
||||||||
|
Description
Chris Lord
2021-04-05 02:42:04 PDT
Created attachment 425144 [details]
Patch
Comment on attachment 425144 [details] Patch View in context: https://bugs.webkit.org/attachment.cgi?id=425144&action=review > Source/WebCore/platform/text/BidiContext.cpp:65 > + static BidiContext* ltrContext; > + static std::once_flag ltrContextOnceFlag; > + std::call_once(ltrContextOnceFlag, [&]() { > + ltrContext = &createUncached(0, U_LEFT_TO_RIGHT, false, FromStyleOrDOM, 0).leakRef(); > + }); > + return *ltrContext; I think the superior idiom is something more like this that does not use leakRef: static NeverDestroyed<RefPtr<BidiContext>> ltrContext; static std::once_flag ltrContextOnceFlag; std::call_once(ltrContextOnceFlag, [&]() { ltrContext = createUncached(0, U_LEFT_TO_RIGHT, false, FromStyleOrDOM, 0); }); return *ltrContext.get(); (In reply to Darin Adler from comment #2) > Comment on attachment 425144 [details] > Patch > > View in context: > https://bugs.webkit.org/attachment.cgi?id=425144&action=review > > > Source/WebCore/platform/text/BidiContext.cpp:65 > > + static BidiContext* ltrContext; > > + static std::once_flag ltrContextOnceFlag; > > + std::call_once(ltrContextOnceFlag, [&]() { > > + ltrContext = &createUncached(0, U_LEFT_TO_RIGHT, false, FromStyleOrDOM, 0).leakRef(); > > + }); > > + return *ltrContext; > > I think the superior idiom is something more like this that does not use > leakRef: > > static NeverDestroyed<RefPtr<BidiContext>> ltrContext; > static std::once_flag ltrContextOnceFlag; > std::call_once(ltrContextOnceFlag, [&]() { > ltrContext = createUncached(0, U_LEFT_TO_RIGHT, false, > FromStyleOrDOM, 0); > }); > return *ltrContext.get(); Funny, I played with this exact structure and not sure why I didn't settle with it... Anyway, I agree, will change. Created attachment 425255 [details]
Patch
Committed r275500: <https://commits.webkit.org/r275500> All reviewed patches have been landed. Closing bug and clearing flags on attachment 425255 [details]. |