Changeset View
Changeset View
Standalone View
Standalone View
source/blender/makesrna/intern/rna_access.c
| Show All 30 Lines | |||||
| #include "DNA_scene_types.h" | #include "DNA_scene_types.h" | ||||
| #include "DNA_windowmanager_types.h" | #include "DNA_windowmanager_types.h" | ||||
| #include "BLI_alloca.h" | #include "BLI_alloca.h" | ||||
| #include "BLI_blenlib.h" | #include "BLI_blenlib.h" | ||||
| #include "BLI_dynstr.h" | #include "BLI_dynstr.h" | ||||
| #include "BLI_ghash.h" | #include "BLI_ghash.h" | ||||
| #include "BLI_math.h" | #include "BLI_math.h" | ||||
| #include "BLI_threads.h" | |||||
| #include "BLI_utildefines.h" | #include "BLI_utildefines.h" | ||||
| #include "BLF_api.h" | #include "BLF_api.h" | ||||
| #include "BLT_translation.h" | #include "BLT_translation.h" | ||||
| #include "BKE_anim_data.h" | #include "BKE_anim_data.h" | ||||
| #include "BKE_collection.h" | #include "BKE_collection.h" | ||||
| #include "BKE_context.h" | #include "BKE_context.h" | ||||
| ▲ Show 20 Lines • Show All 3,624 Lines • ▼ Show 20 Lines | int RNA_property_enum_step( | ||||
| return result_value; | return result_value; | ||||
| } | } | ||||
| PointerRNA RNA_property_pointer_get(PointerRNA *ptr, PropertyRNA *prop) | PointerRNA RNA_property_pointer_get(PointerRNA *ptr, PropertyRNA *prop) | ||||
| { | { | ||||
| PointerPropertyRNA *pprop = (PointerPropertyRNA *)prop; | PointerPropertyRNA *pprop = (PointerPropertyRNA *)prop; | ||||
| IDProperty *idprop; | IDProperty *idprop; | ||||
| static ThreadMutex lock = BLI_MUTEX_INITIALIZER; | |||||
| BLI_assert(RNA_property_type(prop) == PROP_POINTER); | BLI_assert(RNA_property_type(prop) == PROP_POINTER); | ||||
| if ((idprop = rna_idproperty_check(&prop, ptr))) { | if ((idprop = rna_idproperty_check(&prop, ptr))) { | ||||
| pprop = (PointerPropertyRNA *)prop; | pprop = (PointerPropertyRNA *)prop; | ||||
| if (RNA_struct_is_ID(pprop->type)) { | if (RNA_struct_is_ID(pprop->type)) { | ||||
| return rna_pointer_inherit_refine(ptr, pprop->type, IDP_Id(idprop)); | return rna_pointer_inherit_refine(ptr, pprop->type, IDP_Id(idprop)); | ||||
| } | } | ||||
| /* for groups, data is idprop itself */ | /* for groups, data is idprop itself */ | ||||
| if (pprop->type_fn) { | if (pprop->type_fn) { | ||||
| return rna_pointer_inherit_refine(ptr, pprop->type_fn(ptr), idprop); | return rna_pointer_inherit_refine(ptr, pprop->type_fn(ptr), idprop); | ||||
| } | } | ||||
| return rna_pointer_inherit_refine(ptr, pprop->type, idprop); | return rna_pointer_inherit_refine(ptr, pprop->type, idprop); | ||||
| } | } | ||||
| if (pprop->get) { | if (pprop->get) { | ||||
| return pprop->get(ptr); | return pprop->get(ptr); | ||||
| } | } | ||||
| if (prop->flag & PROP_IDPROPERTY) { | if (prop->flag & PROP_IDPROPERTY) { | ||||
| /* XXX temporary hack to add it automatically, reading should | /* NOTE: While creating/writing data in an accessor is really bad design-wise, this is | ||||
| * never do any write ops, to ensure thread safety etc. */ | * currently very difficult to avoid in that case. So a global mutex is used to keep ensuring | ||||
| * thread safety. */ | |||||
| BLI_mutex_lock(&lock); | |||||
| /* NOTE: We do not need to check again for existence of the pointer after locking here, since | |||||
| * this is also done in #RNA_property_pointer_add itself. */ | |||||
| RNA_property_pointer_add(ptr, prop); | RNA_property_pointer_add(ptr, prop); | ||||
| BLI_mutex_unlock(&lock); | |||||
brecht: Can we lock only when the pointer does not exist yet, inside `RNA_property_pointer_add`?
We… | |||||
Done Inline ActionsNot sure I understand that comment? RNA_pointer_add() also calls RNA_property_pointer_add, so adding the lock inside RNA_property_pointer_add would actually make it used more often? Further more, we already checked at the beginning of that function (RNA_property_pointer_get) that this is not currently allocated (the idprop = rna_idproperty_check(&prop, ptr) in the first if) ? So I think locking here is the best solution? Also missing a comment about why we do not check again for existence after locking here (since it's done by RNA_property_pointer_add itself), will add with update for the other remarks. mont29: Not sure I understand that comment? `RNA_pointer_add()` also calls `RNA_property_pointer_add`… | |||||
| return RNA_property_pointer_get(ptr, prop); | return RNA_property_pointer_get(ptr, prop); | ||||
| } | } | ||||
| return PointerRNA_NULL; | return PointerRNA_NULL; | ||||
| } | } | ||||
| void RNA_property_pointer_set(PointerRNA *ptr, | void RNA_property_pointer_set(PointerRNA *ptr, | ||||
| PropertyRNA *prop, | PropertyRNA *prop, | ||||
| PointerRNA ptr_value, | PointerRNA ptr_value, | ||||
| ▲ Show 20 Lines • Show All 4,541 Lines • Show Last 20 Lines | |||||
Can we lock only when the pointer does not exist yet, inside RNA_property_pointer_add?
We might access this many times, but only rarely do we actually need to allocate something.