Jelajahi Sumber

Add two new script functions to control delayed release hooks calls.

mingodad 12 tahun lalu
induk
melakukan
bc7bb7507b

+ 18 - 0
SquiLu/squirrel/sqbaselib.cpp

@@ -65,6 +65,22 @@ static SQRESULT base_getrefcount(HSQUIRRELVM v)
     else sq_pushinteger(v, o._unVal.pRefCounted->_uiRef - 1);
     else sq_pushinteger(v, o._unVal.pRefCounted->_uiRef - 1);
 	return 1;
 	return 1;
 }
 }
+static SQRESULT base_check_delayed_release_hooks(HSQUIRRELVM v)
+{
+	SQ_FUNC_VARS(v);
+	if(_top_ > 1){
+		SQ_GET_BOOL(v, 2, bval);
+		v->_check_delayed_relase_hooks = bval;
+		return 0;
+	}
+    sq_pushbool(v, v->_check_delayed_relase_hooks);
+	return 1;
+}
+static SQRESULT base_call_delayed_release_hooks(HSQUIRRELVM v)
+{
+    v->_sharedstate->CallDelayedReleaseHooks(v);
+	return 0;
+}
 #endif
 #endif
 
 
 static SQRESULT base_getroottable(HSQUIRRELVM v)
 static SQRESULT base_getroottable(HSQUIRRELVM v)
@@ -394,6 +410,8 @@ static SQRegFunction base_funcs[]={
 	{_SC("collectgarbage"),base_collectgarbage,0, NULL},
 	{_SC("collectgarbage"),base_collectgarbage,0, NULL},
 	{_SC("resurrectunreachable"),base_resurectureachable,0, NULL},
 	{_SC("resurrectunreachable"),base_resurectureachable,0, NULL},
 	{_SC("getrefcount"),base_getrefcount,2, _SC("..")},
 	{_SC("getrefcount"),base_getrefcount,2, _SC("..")},
+	{_SC("check_delayed_release_hooks"),base_check_delayed_release_hooks,-1, _SC(".b")},
+	{_SC("call_delayed_release_hooks"),base_call_delayed_release_hooks,1, NULL},
 #endif
 #endif
 	{_SC("str_from_chars"),base_str_from_chars,-2, _SC(".i")},
 	{_SC("str_from_chars"),base_str_from_chars,-2, _SC(".i")},
 	{0,0}
 	{0,0}

+ 7 - 9
SquiLu/squirrel/sqobject.h

@@ -92,7 +92,7 @@ struct SQRefCounted
 	virtual ~SQRefCounted();
 	virtual ~SQRefCounted();
 	SQWeakRef *GetWeakRef(SQObjectType type);
 	SQWeakRef *GetWeakRef(SQObjectType type);
 	virtual void Release()=0;
 	virtual void Release()=0;
-	
+
 };
 };
 
 
 struct SQWeakRef : SQRefCounted
 struct SQWeakRef : SQRefCounted
@@ -108,7 +108,7 @@ struct SQObjectPtr;
 #define __AddRef(type,unval) if(ISREFCOUNTED(type))	\
 #define __AddRef(type,unval) if(ISREFCOUNTED(type))	\
 		{ \
 		{ \
 			unval.pRefCounted->_uiRef++; \
 			unval.pRefCounted->_uiRef++; \
-		}  
+		}
 
 
 #define __Release(type,unval) if(ISREFCOUNTED(type) && ((--unval.pRefCounted->_uiRef)==0))	\
 #define __Release(type,unval) if(ISREFCOUNTED(type) && ((--unval.pRefCounted->_uiRef)==0))	\
 		{	\
 		{	\
@@ -176,10 +176,8 @@ struct SQObjectPtr;
 	} \
 	} \
 	inline SQObjectPtr& operator=(_class *x) \
 	inline SQObjectPtr& operator=(_class *x) \
 	{  \
 	{  \
-		SQObjectType tOldType; \
-		SQObjectValue unOldVal; \
-		tOldType=_type; \
-		unOldVal=_unVal; \
+		SQObjectType tOldType=_type; \
+		SQObjectValue unOldVal=_unVal; \
 		_type = type; \
 		_type = type; \
 		SQ_REFOBJECT_INIT() \
 		SQ_REFOBJECT_INIT() \
 		_unVal.sym = x; \
 		_unVal.sym = x; \
@@ -236,7 +234,7 @@ struct SQObjectPtr : public SQObject
 	_REF_TYPE_DECL(OT_WEAKREF,SQWeakRef,pWeakRef)
 	_REF_TYPE_DECL(OT_WEAKREF,SQWeakRef,pWeakRef)
 	_REF_TYPE_DECL(OT_THREAD,SQVM,pThread)
 	_REF_TYPE_DECL(OT_THREAD,SQVM,pThread)
 	_REF_TYPE_DECL(OT_FUNCPROTO,SQFunctionProto,pFunctionProto)
 	_REF_TYPE_DECL(OT_FUNCPROTO,SQFunctionProto,pFunctionProto)
-	
+
 	_SCALAR_TYPE_DECL(OT_INTEGER,SQInteger,nInteger)
 	_SCALAR_TYPE_DECL(OT_INTEGER,SQInteger,nInteger)
 	_SCALAR_TYPE_DECL(OT_FLOAT,SQFloat,fFloat)
 	_SCALAR_TYPE_DECL(OT_FLOAT,SQFloat,fFloat)
 	_SCALAR_TYPE_DECL(OT_USERPOINTER,SQUserPointer,pUserPointer)
 	_SCALAR_TYPE_DECL(OT_USERPOINTER,SQUserPointer,pUserPointer)
@@ -248,7 +246,7 @@ struct SQObjectPtr : public SQObject
 		_unVal.nInteger = bBool?1:0;
 		_unVal.nInteger = bBool?1:0;
 	}
 	}
 	inline SQObjectPtr& operator=(bool b)
 	inline SQObjectPtr& operator=(bool b)
-	{ 
+	{
 		__Release(_type,_unVal);
 		__Release(_type,_unVal);
 		SQ_OBJECT_RAWINIT()
 		SQ_OBJECT_RAWINIT()
 		_type = OT_BOOL;
 		_type = OT_BOOL;
@@ -260,7 +258,7 @@ struct SQObjectPtr : public SQObject
 	{
 	{
 		__Release(_type,_unVal);
 		__Release(_type,_unVal);
 	}
 	}
-			
+
 	inline SQObjectPtr& operator=(const SQObjectPtr& obj)
 	inline SQObjectPtr& operator=(const SQObjectPtr& obj)
 	{
 	{
 		SQObjectType tOldType =_type;
 		SQObjectType tOldType =_type;

+ 4 - 2
SquiLu/squirrel/sqvm.cpp

@@ -134,7 +134,8 @@ SQVM::SQVM(SQSharedState *ss)
 	_debughook_closure.Null();
 	_debughook_closure.Null();
 	_openouters = NULL;
 	_openouters = NULL;
 	ci = NULL;
 	ci = NULL;
-	INIT_CHAIN();ADD_TO_CHAIN(&_ss(this)->_gc_chain,this);
+	INIT_CHAIN();ADD_TO_CHAIN(&_ss(this)->_gc_chain,this);
+	_check_delayed_relase_hooks = true;
 }
 }
 
 
 void SQVM::Finalize()
 void SQVM::Finalize()
@@ -751,7 +752,8 @@ exception_restore:
 		for(;;)
 		for(;;)
 		{
 		{
 		    //if the last instruction was a call then check for release hooks
 		    //if the last instruction was a call then check for release hooks
-		    if(ci->_ip->op == _OP_CALL) _sharedstate->CallDelayedReleaseHooks(this);
+		    //obs.: changing the order of comparison bellow with gcc makes the code slower
+		    if((ci->_ip->op == _OP_CALL) && _check_delayed_relase_hooks) _sharedstate->CallDelayedReleaseHooks(this);
 			const SQInstruction &_i_ = *ci->_ip++;
 			const SQInstruction &_i_ = *ci->_ip++;
 			//dumpstack(_stackbase);
 			//dumpstack(_stackbase);
 			//scprintf("\n[%d] %s %d %d %d %d\n",ci->_ip-ci->_iv->_vals,g_InstrDesc[_i_.op].name,arg0,arg1,arg2,arg3);
 			//scprintf("\n[%d] %s %d %d %d %d\n",ci->_ip-ci->_iv->_vals,g_InstrDesc[_i_.op].name,arg0,arg1,arg2,arg3);

+ 2 - 1
SquiLu/squirrel/sqvm.h

@@ -176,7 +176,8 @@ public:
 	SQInteger _nmetamethodscall;
 	SQInteger _nmetamethodscall;
 	//suspend infos
 	//suspend infos
 	SQBool _suspended;
 	SQBool _suspended;
-	SQBool _suspended_root;
+	SQBool _suspended_root;
+	SQBool _check_delayed_relase_hooks;
 	SQInteger _suspended_target;
 	SQInteger _suspended_target;
 	SQInteger _suspended_traps;
 	SQInteger _suspended_traps;
 };
 };