- Timestamp:
- Nov 27, 2006, 2:50:43 AM (18 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
Include/system/gc.sbp
r1 r18 29 29 iAllSize As SIZE_T 30 30 31 'スレッド情報32 phThread As *HANDLE33 pStackBase As **LONG_PTR34 ThreadNum As Long35 36 31 CriticalSection As CRITICAL_SECTION 37 32 … … 47 42 iAllSize=0 48 43 49 'スレッド情報 50 phThread=HeapAlloc(_System_hProcessHeap,0,1) 51 pStackBase=HeapAlloc(_System_hProcessHeap,0,1) 52 ThreadNum=0 44 'スレッド情報管理用オブジェクトを生成 45 _System_pobj_AllThreads=_System_malloc(SizeOf(_System_CThreadCollection)+SizeOf(LONG_PTR)) 46 _System_pobj_AllThreads->_System_CThreadCollection() 53 47 54 48 'クリティカルセッションを生成 55 49 InitializeCriticalSection(CriticalSection) 56 50 57 '開始時のスレッドを通知 51 52 '--------------------------- 53 ' 開始時のスレッドを通知 54 '--------------------------- 58 55 Dim hTargetThread As HANDLE 59 56 DuplicateHandle(GetCurrentProcess(), … … 61 58 GetCurrentProcess(), 62 59 hTargetThread, 0, FALSE, DUPLICATE_SAME_ACCESS) 'カレントスレッドのハンドルを複製 63 BeginThread(hTargetThread,_System_gc_StackRoot_StartPtr As *LONG_PTR) 60 61 62 '自身のThreadオブジェクトを生成 63 Dim obj_Thread As Thread(hTargetThread,GetCurrentThreadId(),0) 64 65 _System_pobj_AllThreads->BeginThread(obj_Thread,_System_gc_StackRoot_StartPtr As *LONG_PTR) 64 66 End Sub 65 67 Sub ~_System_CGarbageCollection() … … 79 81 ' すべてのスレッドを一時停止 80 82 '------------------------------------- 83 _System_pobj_AllThreads->SuspendAllThread() 84 85 81 86 Dim i As Long 82 For i=0 To ELM(ThreadNum)83 If phThread[i] Then84 SuspendThread(phThread[i])85 End If86 Next87 88 89 87 For i=0 To ELM(n) 90 88 If ppPtr[i] Then HeapFree(_System_hProcessHeap,0,ppPtr[i]) … … 98 96 pbFlags=0 99 97 100 'スレッド情報 101 HeapFree(_System_hProcessHeap,0,phThread) 102 phThread=0 103 HeapFree(_System_hProcessHeap,0,pStackBase) 104 pStackBase=0 98 'スレッド情報管理用オブジェクトを破棄 99 _System_pobj_AllThreads->Finalize() 100 _System_free(_System_pobj_AllThreads) 101 _System_pobj_AllThreads=0 105 102 106 103 'クリティカルセッションを破棄 … … 159 156 160 157 Function __realloc(lpMem As VoidPtr, size As SIZE_T) As VoidPtr 161 Dim i As Long 162 For i=0 To ELM(n) 163 If ppPtr[i]=lpMem Then 164 iAllSize+=size-pSize[i] 165 166 pSize[i]=size 167 ppPtr[i]=HeapReAlloc(_System_hProcessHeap,HEAP_ZERO_MEMORY,lpMem,size) 168 Return ppPtr[i] 169 End If 170 Next 158 EnterCriticalSection(CriticalSection) 159 Dim i As Long 160 For i=0 To ELM(n) 161 If ppPtr[i]=lpMem Then 162 iAllSize+=size-pSize[i] 163 164 pSize[i]=size 165 ppPtr[i]=HeapReAlloc(_System_hProcessHeap,HEAP_ZERO_MEMORY,lpMem,size) 166 167 LeaveCriticalSection(CriticalSection) 168 Return ppPtr[i] 169 End If 170 Next 171 LeaveCriticalSection(CriticalSection) 171 172 Return 0 172 173 End Function 173 174 174 175 Sub __free(lpMem As VoidPtr) 175 Dim i As Long 176 For i=0 To ELM(n) 177 If ppPtr[i]=lpMem Then 178 If pbFlags[i] and _System_GC_FLAG_NEEDFREE Then 179 iAllSize-=pSize[i] 180 181 HeapFree(_System_hProcessHeap,0,ppPtr[i]) 182 ppPtr[i]=0 183 pSize[i]=0 184 Else 185 OutputDebugString(Ex"GCが管理しているメモリ空間を解放しようとしました。\r\n") 176 EnterCriticalSection(CriticalSection) 177 Dim i As Long 178 For i=0 To ELM(n) 179 If ppPtr[i]=lpMem Then 180 If pbFlags[i] and _System_GC_FLAG_NEEDFREE Then 181 iAllSize-=pSize[i] 182 183 HeapFree(_System_hProcessHeap,0,ppPtr[i]) 184 ppPtr[i]=0 185 pSize[i]=0 186 Else 187 OutputDebugString(Ex"GCが管理しているメモリ空間を解放しようとしました。\r\n") 188 End If 186 189 End If 187 End If188 Next190 Next 191 LeaveCriticalSection(CriticalSection) 189 192 End Sub 190 193 … … 212 215 ' すべてのスレッドを一時停止 213 216 '------------------------------------- 214 Dim i As Long 215 For i=0 To ELM(ThreadNum) 216 If phThread[i] Then 217 SuspendThread(phThread[i]) 218 End If 219 Next 217 _System_pobj_AllThreads->SuspendAllThread() 220 218 221 219 … … 232 230 'ローカル領域をルートに指定してスキャン 233 231 '----------------------------------------------- 232 Dim Context As CONTEXT 234 233 Dim NowSp As *LONG_PTR 235 Dim Context As CONTEXT236 234 Dim size As LONG_PTR 237 For i=0 To ELM(ThreadNum) 238 If phThread[i] Then 235 Dim i As Long 236 For i=0 To ELM(_System_pobj_AllThreads->ThreadNum) 237 If _System_pobj_AllThreads->ppobj_Thread[i] Then 239 238 FillMemory(VarPtr(Context),SizeOf(CONTEXT),0) 240 239 Context.ContextFlags=CONTEXT_CONTROL 241 If GetThreadContext(phThread[i],Context)=0 Then240 If _System_pobj_AllThreads->ppobj_Thread[i]->__GetContext(Context)=0 Then 242 241 OutputDebugString(Ex"レジスタ情報の取得に失敗しました。\r\n") 243 242 End If … … 249 248 #endif 250 249 251 size=( pStackBase[i] As LONG_PTR)-(NowSp As LONG_PTR)250 size=(_System_pobj_AllThreads->pStackBase[i] As LONG_PTR)-(NowSp As LONG_PTR) 252 251 253 252 scan(NowSp,size) … … 282 281 ' すべてのスレッドを再開 283 282 '------------------------------------- 284 For i=0 To ELM(ThreadNum) 285 If phThread[i] Then 286 ResumeThread(phThread[i]) 287 End If 288 Next 289 End Function 290 291 292 293 '---------------------------- 294 ' スレッド制御のメソッド 295 '---------------------------- 296 Sub BeginThread(hThread As HANDLE,NowSp As *LONG_PTR) 297 EnterCriticalSection(CriticalSection) 298 Dim i As Long 299 For i=0 To ELM(ThreadNum) 300 If phThread[i]=0 Then 301 phThread[i]=hThread 302 pStackBase[i]=NowSp 303 Exit For 304 End If 305 Next 306 307 If i=ThreadNum Then 308 phThread=HeapReAlloc(_System_hProcessHeap,0,phThread,(ThreadNum+1)*SizeOf(HANDLE)) 309 phThread[ThreadNum]=hThread 310 pStackBase=HeapReAlloc(_System_hProcessHeap,0,pStackBase,(ThreadNum+1)*SizeOf(LONG_PTR)) 311 pStackBase[ThreadNum]=NowSp 312 ThreadNum++ 313 End If 314 LeaveCriticalSection(CriticalSection) 315 End Sub 316 Sub EndThread(hThread As HANDLE) 317 EnterCriticalSection(CriticalSection) 318 Dim i As Long 319 For i=0 To ELM(ThreadNum) 320 If phThread[i]=hThread Then 321 phThread[i]=0 322 pStackBase[i]=0 323 Exit For 324 End If 325 Next 326 LeaveCriticalSection(CriticalSection) 327 End Sub 283 _System_pobj_AllThreads->ResumeAllThread() 284 End Function 328 285 329 286
Note:
See TracChangeset
for help on using the changeset viewer.