瀏覽代碼

Changed GC finalizer.
Fixed TList issues using new finalizer.

woollybah 6 年之前
父節點
當前提交
cf296b58aa
共有 4 個文件被更改,包括 25 次插入58 次删除
  1. 1 0
      blitz.mod/blitz.bmx
  2. 2 2
      blitz.mod/blitz_gc.c
  3. 1 0
      glmax2d.mod/glmax2d.bmx
  4. 21 56
      linkedlist.mod/linkedlist.bmx

+ 1 - 0
blitz.mod/blitz.bmx

@@ -74,6 +74,7 @@ ModuleInfo "CC_OPTS: -DNO_GETCONTEXT"
 ?nx
 ModuleInfo "CC_OPTS: -DATOMIC_UNCOLLECTABLE -DNN_BUILD_TARGET_PLATFORM_NX"
 ?
+ModuleInfo "CC_OPTS: -DJAVA_FINALIZATION"
 
 ?debug
 ModuleInfo "CC_OPTS: -DBMX_DEBUG"

+ 2 - 2
blitz.mod/blitz_gc.c

@@ -75,7 +75,7 @@ BBGCMem *bbGCAlloc( int sz,BBGCPool *pool ){
 	BBGCMem *q=(BBGCMem*) GC_MALLOC( sz );
 	q->pool=pool;
 	//q->refs=-1;
-	GC_REGISTER_FINALIZER( q,gc_finalizer,pool,&ofn,&ocd );
+	GC_REGISTER_FINALIZER_NO_ORDER( q,gc_finalizer,pool,&ofn,&ocd );
 	return q;
 }
 
@@ -91,7 +91,7 @@ BBObject * bbGCAllocObject( int sz,BBClass *clas,int flags ){
 	if( flags & BBGC_FINALIZE ){
 		GC_finalization_proc ofn;
 		void *ocd;
-		GC_REGISTER_FINALIZER( q,gc_finalizer,clas,&ofn,&ocd );
+		GC_REGISTER_FINALIZER_NO_ORDER( q,gc_finalizer,clas,&ofn,&ocd );
 	}
 	return q;	
 }

+ 1 - 0
glmax2d.mod/glmax2d.bmx

@@ -37,6 +37,7 @@ ModuleInfo "History: Added checks to prevent invalid textures deletes"
 
 Import BRL.Max2D
 Import BRL.GLGraphics
+Import BRL.Threads
 
 Private
 

+ 21 - 56
linkedlist.mod/linkedlist.bmx

@@ -6,12 +6,14 @@ bbdoc: Data structures/Linked lists
 End Rem
 Module BRL.LinkedList
 
-ModuleInfo "Version: 1.10"
+ModuleInfo "Version: 1.11"
 ModuleInfo "Author: Mark Sibly"
 ModuleInfo "License: zlib/libpng"
 ModuleInfo "Copyright: Blitz Research Ltd"
 ModuleInfo "Modserver: BRL"
 
+ModuleInfo "History: 1.11"
+ModuleInfo "History: Fixed Delete issues with revised GC finalizer."
 ModuleInfo "History: 1.10"
 ModuleInfo "History: Fixed TLink removal during iteration issue."
 ModuleInfo "History: 1.09"
@@ -27,10 +29,6 @@ ModuleInfo "History: Added optional CompareFunc parameter to Sort"
 ModuleInfo "History: 1.05 Release"
 ModuleInfo "History: Sort now swaps links instead of values"
 
-?Threaded
-Import BRL.Threads
-?
-
 Function CompareObjects( o1:Object,o2:Object )
 	Return o1.Compare( o2 )
 End Function
@@ -42,7 +40,6 @@ Type TLink
 
 	Field _value:Object
 	Field _succ:TLink,_pred:TLink
-	Field _removed:Int
 	
 	Rem
 	bbdoc: Returns the Object associated with this Link.
@@ -72,9 +69,6 @@ Type TLink
 		_value=Null
 		_succ._pred=_pred
 		_pred._succ=_succ
-		_removed = True
-		_pred=Null
-		_succ=Null
 	End Method
 
 End Type
@@ -84,29 +78,10 @@ bbdoc: Enumerator Object use by TList in order to implement Eachin support.
 End Rem
 Type TListEnum
 
-	Global _pool:TList = New TList
-?Threaded
-	Global _mutex:TMutex = CreateMutex()
-?
-
 	Field _link:TLink
-	Field _list:TList
 
 	Method HasNext()
-		Local has:Int = _link._value<>_link And Not _link._removed
-		If Not has Then
-?Threaded
-			LockMutex(_mutex)
-?
-			_pool.AddLast(Self)
-
-			_link = Null
-			_list = Null
-?Threaded
-			UnlockMutex(_mutex)
-?
-		End If
-		Return has
+		Return _link._value<>_link
 	End Method
 
 	Method NextObject:Object()
@@ -139,10 +114,10 @@ Type TList
 	
 '?Not Threaded
 	Method Delete()
-		Clear
-		_head._value=Null
-		_head._succ=Null
-		_head._pred=Null
+'		Clear
+'		_head._value=Null
+'		_head._succ=Null
+'		_head._pred=Null
 	End Method
 '?
 	Rem
@@ -408,7 +383,6 @@ Type TList
 	Method Sort( ascending=True,compareFunc( o1:Object,o2:Object )=CompareObjects )
 		Local ccsgn=-1
 		If ascending ccsgn=1
-		Local modded:Int
 		
 		Local insize=1
 		Repeat
@@ -452,7 +426,6 @@ Type TList
 					t._pred=tail
 					tail._succ=t
 					tail=t
-					modded = True
 				Forever
 				p=q
 			Wend
@@ -469,18 +442,8 @@ Type TList
 	End Method
 		
 	Method ObjectEnumerator:TListEnum()
-?Threaded
-			LockMutex(TListEnum._mutex)
-?
-		Local enumeration:TListEnum=TListEnum(TListEnum._pool.RemoveFirst())
-?Threaded
-			UnlockMutex(TListEnum._mutex)
-?
-		If Not enumeration Then
-			enumeration = New TListEnum
-		End If
+		Local enumeration:TListEnum=New TListEnum
 		enumeration._link=_head._succ
-		enumeration._list = Self
 		Return enumeration
 	End Method
 
@@ -511,12 +474,22 @@ Type TList
 		Return list
 	End Function
 
+	Rem
+	bbdoc: Remove an object from a linked list.
+	End Rem
+	Method RemoveLink( link:TLink )
+		If _count > -1 Then
+			_count :- 1
+		End If
+		link.Remove
+	End Method
+	
 End Type
 
 Rem
 bbdoc: Create a linked list
 returns: A new linked list object
-end rem
+End Rem
 Function CreateList:TList()
 	Return New TList
 End Function
@@ -617,15 +590,7 @@ End Function
 Rem
 bbdoc: Remove an object from a linked list
 about: #ListRemove scans a list for the specified value and removes its link.
-end rem
+End Rem
 Function ListRemove( list:TList,value:Object )
 	list.Remove value
 End Function
-
-Rem
-bbdoc: Remove an object from a linked list
-about: #RemoveLink is more efficient than #ListRemove.
-end rem
-Function RemoveLink( link:TLink )
-	link.Remove
-End Function