[K/N] Dispose ObjC objects from main thread on main thread. ^KT-56402
Merge-request: KT-MR-9515 Merged-by: Alexander Shabalin <Alexander.Shabalin@jetbrains.com>
This commit is contained in:
committed by
Space Team
parent
5282e60328
commit
82f94015f1
@@ -43,11 +43,27 @@ void* ObjHeader::GetAssociatedObject() const {
|
||||
}
|
||||
|
||||
void ObjHeader::SetAssociatedObject(void* obj) {
|
||||
return mm::ExtraObjectData::FromMetaObjHeader(meta_object()).AssociatedObject().store(obj, std::memory_order_release);
|
||||
auto& extraObject = mm::ExtraObjectData::FromMetaObjHeader(meta_object());
|
||||
// TODO: Consider additional filtering based on types:
|
||||
// * have some kind of an allowlist that can be populated by the user
|
||||
// to specify that objects of these types must be finalized only on
|
||||
// the main thread.
|
||||
// * prepopulate it for the system frameworks.
|
||||
// * if that were to be done at runtime, library authors could register
|
||||
// their types in a library initialization code.
|
||||
if (pthread_main_np() == 1) {
|
||||
extraObject.setFlag(mm::ExtraObjectData::FLAGS_RELEASE_ON_MAIN_QUEUE);
|
||||
}
|
||||
return extraObject.AssociatedObject().store(obj, std::memory_order_release);
|
||||
}
|
||||
|
||||
void* ObjHeader::CasAssociatedObject(void* expectedObj, void* obj) {
|
||||
mm::ExtraObjectData::FromMetaObjHeader(meta_object()).AssociatedObject().compare_exchange_strong(expectedObj, obj);
|
||||
auto& extraObject = mm::ExtraObjectData::FromMetaObjHeader(meta_object());
|
||||
bool success = extraObject.AssociatedObject().compare_exchange_strong(expectedObj, obj);
|
||||
// TODO: Consider additional filtering outlined above.
|
||||
if (success && pthread_main_np() == 1) {
|
||||
extraObject.setFlag(mm::ExtraObjectData::FLAGS_RELEASE_ON_MAIN_QUEUE);
|
||||
}
|
||||
return expectedObj;
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user