[Bf-blender-cvs] [da53656] asset-experiments: Add refcounting and shallow copy to AssetEngine.

Bastien Montagne noreply at git.blender.org
Thu Mar 12 11:07:39 CET 2015


Commit: da53656be163b09c0a021d5300ea4121171c88bb
Author: Bastien Montagne
Date:   Tue Mar 10 12:52:25 2015 +0100
Branches: asset-experiments
https://developer.blender.org/rBda53656be163b09c0a021d5300ea4121171c88bb

Add refcounting and shallow copy to AssetEngine.

Reason is, we want operator to 'inherit' ae instance from spacefile too.

===================================================================

M	source/blender/blenkernel/BKE_asset.h
M	source/blender/blenkernel/intern/asset.c

===================================================================

diff --git a/source/blender/blenkernel/BKE_asset.h b/source/blender/blenkernel/BKE_asset.h
index e4726cd..a0b6b65 100644
--- a/source/blender/blenkernel/BKE_asset.h
+++ b/source/blender/blenkernel/BKE_asset.h
@@ -117,6 +117,7 @@ typedef struct AssetEngine {
 	void *py_instance;
 
 	int flag;
+	int refcount;
 
 	struct ReportList *reports;
 } AssetEngine;
@@ -129,6 +130,7 @@ AssetEngineType *BKE_asset_engines_find(const char *idname);
 
 /* Engine Instances */
 AssetEngine *BKE_asset_engine_create(AssetEngineType *type);
+AssetEngine *BKE_asset_engine_copy(AssetEngine *engine);
 void BKE_asset_engine_free(AssetEngine *engine);
 
 #ifdef __cplusplus
diff --git a/source/blender/blenkernel/intern/asset.c b/source/blender/blenkernel/intern/asset.c
index c16b601..43fa1b4 100644
--- a/source/blender/blenkernel/intern/asset.c
+++ b/source/blender/blenkernel/intern/asset.c
@@ -106,17 +106,27 @@ AssetEngine *BKE_asset_engine_create(AssetEngineType *type)
 
 	engine = MEM_callocN(sizeof(AssetEngine), __func__);
 	engine->type = type;
+	engine->refcount = 1;
 
 	return engine;
 }
 
+/** Shalow copy only (i.e. memory is 100% shared, just increases refcount). */
+AssetEngine *BKE_asset_engine_copy(AssetEngine *engine)
+{
+	engine->refcount++;
+	return engine;
+}
+
 void BKE_asset_engine_free(AssetEngine *engine)
 {
+	if (engine->refcount-- == 1) {
 #ifdef WITH_PYTHON
-	if (engine->py_instance) {
-		BPY_DECREF_RNA_INVALIDATE(engine->py_instance);
-	}
+		if (engine->py_instance) {
+			BPY_DECREF_RNA_INVALIDATE(engine->py_instance);
+		}
 #endif
 
-	MEM_freeN(engine);
+		MEM_freeN(engine);
+	}
 }




More information about the Bf-blender-cvs mailing list