- Timestamp:
- Nov 10, 2007, 11:20:01 AM (17 years ago)
- Location:
- trunk
- Files:
-
- 4 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/Include/Classes/System/Threading/Thread.ab
r330 r374 28 28 name As String 29 29 30 isThrowing As Boolean 31 throwingParamObject As Object 32 30 33 Public 31 34 Sub Thread() … … 37 40 38 41 name = "sub thread" 42 43 isThrowing = False 44 throwingParamObject = Nothing 39 45 End Sub 40 46 Sub Thread(fp As PTHREAD_START_ROUTINE, args As VoidPtr) … … 47 53 48 54 name = "sub thread" 55 56 isThrowing = False 57 throwingParamObject = Nothing 49 58 End Sub 50 59 … … 57 66 58 67 name = "sub thread" 68 69 isThrowing = False 70 throwingParamObject = Nothing 59 71 End Sub 60 72 … … 64 76 65 77 name = "sub thread" 78 79 isThrowing = False 80 throwingParamObject = Nothing 66 81 End Sub 67 82 … … 163 178 Function __SetContext(ByRef Context As CONTEXT) As BOOL 164 179 Return SetThreadContext(m_hThread,Context) 180 End Function 181 182 Sub __Throw( ex As Object ) 183 isThrowing = True 184 throwingParamObject = ex 185 End Sub 186 Sub __Catched() 187 isThrowing = False 188 throwingParamObject = Nothing 189 End Sub 190 Function __IsThrowing() As Boolean 191 Return isThrowing 192 End Function 193 Function __GetThrowintParamObject() As Object 194 Return throwingParamObject 165 195 End Function 166 196 -
trunk/Include/system/exception.ab
r373 r374 3 3 Class TryLayer 4 4 Public 5 Const addressOfCatch As VoidPtr 5 Const catchTable As *LONG_PTR 6 Const addressOfFinally As VoidPtr 6 7 Const basePtr As LONG_PTR 7 8 Const stackPtr As LONG_PTR 9 8 10 Const debugProcNum As DWord 9 11 10 Sub TryLayer( addressOfCatch As VoidPtr, basePtr As LONG_PTR, stackPtr As LONG_PTR ) 11 This.addressOfCatch = addressOfCatch 12 Sub TryLayer( catchTable As *LONG_PTR, addressOfFinally As VoidPtr, basePtr As LONG_PTR, stackPtr As LONG_PTR ) 13 This.catchTable = catchTable 14 This.addressOfFinally = addressOfFinally 12 15 This.basePtr = basePtr 13 16 This.stackPtr = stackPtr … … 23 26 Sub ~TryLayer() 24 27 End Sub 28 29 Sub FinishFinally() 30 If Thread.CurrentThread().__IsThrowing() Then 31 Throw Thread.CurrentThread().__GetThrowintParamObject() 32 End If 33 End Sub 34 35 Function ResolveCatchesOverload( ex As Object ) As LONG_PTR 36 Dim defaultCatchCodePos = 0 As LONG_PTR 37 Dim pos = 0 As Long 38 While catchTable[pos] 39 ' パラメータのクラス名 40 Dim paramName = catchTable[pos] As *Char 41 pos ++ 42 43 ' コード位置 44 Dim codePos = catchTable[pos] As LONG_PTR 45 pos ++ 46 47 If paramName[0] = 0 Then 48 ' Default Catch 49 defaultCatchCodePos = codePos 50 End If 51 52 If Object.ReferenceEquals( ex, Nothing ) Then 53 ' パラメータなしのとき 54 If paramName[0] = 0 Then 55 ' マッチしたとき 56 Return codePos 57 End If 58 Else 59 If lstrcmp( paramName, ex.GetType().FullName ) = 0 Then 60 ' マッチしたとき 61 Return codePos 62 End If 63 End If 64 Wend 65 Return defaultCatchCodePos 66 End Function 25 67 End Class 26 68 … … 48 90 49 91 'Try 50 Function _BeginTryScope( addressOfCatchAs VoidPtr, basePtr As LONG_PTR, stackPtr As LONG_PTR ) As TryLayer92 Function _BeginTryScope( catchTable As *LONG_PTR, addressOfFinally As VoidPtr, basePtr As LONG_PTR, stackPtr As LONG_PTR ) As TryLayer 51 93 ppTryLayers = _System_realloc( ppTryLayers, ( nTryLayers + 1 ) * SizeOf( *TryLayer ) ) 52 ppTryLayers[nTryLayers] = New TryLayer( addressOfCatch, basePtr, stackPtr )94 ppTryLayers[nTryLayers] = New TryLayer( catchTable, addressOfFinally, basePtr, stackPtr ) 53 95 nTryLayers++ 54 96 … … 56 98 End Function 57 99 58 Static Function BeginTryScope( addressOfCatchAs VoidPtr, basePtr As LONG_PTR, stackPtr As LONG_PTR ) As TryLayer59 Return _System_pobj_AllThreads->GetCurrentException()->_BeginTryScope( addressOfCatch, basePtr, stackPtr )100 Static Function BeginTryScope( catchTable As *LONG_PTR, addressOfFinally As VoidPtr, basePtr As LONG_PTR, stackPtr As LONG_PTR ) As TryLayer 101 Return _System_pobj_AllThreads->GetCurrentException()->_BeginTryScope( catchTable, addressOfFinally, basePtr, stackPtr ) 60 102 End Function 61 103 … … 67 109 68 110 'Throw 69 Sub _Throw( )111 Sub _Throw( ex As Object ) 70 112 If nTryLayers <= 0 then 71 113 '例外処理スコープ制御が無効なとき … … 77 119 End If 78 120 121 ' スレッドへThrow処理を開始したことを通知 122 Thread.CurrentThread().__Throw( ex ) 123 79 124 '未解放なローカルオブジェクトを解放する 80 125 FreeLocalObjects() 81 126 127 Dim pTryLayer = ppTryLayers[nTryLayers - 1] As *TryLayer 128 129 Dim addressOfCatch = pTryLayer->ResolveCatchesOverload( ex ) As LONG_PTR 130 If addressOfCatch Then 131 ' スレッドへThrow処理が終了した(Catchされた)ことを通知 132 Thread.CurrentThread().__Catched() 133 Else 134 ' Catchが定義されていないときはFinallyへ誘導 135 addressOfCatch = pTryLayer->addressOfFinally As LONG_PTR 136 End If 82 137 83 138 … … 95 150 '新しいip, sp, bpをセット 96 151 #ifdef _WIN64 97 context.Rip = ppTryLayers[nTryLayers - 1]->addressOfCatch As QWord98 context.Rbp = p pTryLayers[nTryLayers - 1]->basePtr99 context.Rsp = p pTryLayers[nTryLayers - 1]->stackPtr152 context.Rip = addressOfCatch As QWord 153 context.Rbp = pTryLayer->basePtr 154 context.Rsp = pTryLayer->stackPtr 100 155 #else 101 context.Eip = ppTryLayers[nTryLayers - 1]->addressOfCatch As DWord102 context.Ebp = p pTryLayers[nTryLayers - 1]->basePtr103 context.Esp = p pTryLayers[nTryLayers - 1]->stackPtr156 context.Eip = addressOfCatch As DWord 157 context.Ebp = pTryLayer->basePtr 158 context.Esp = pTryLayer->stackPtr 104 159 #endif 105 160 … … 108 163 ThreadNum=_DebugSys_GetThread() 109 164 If ThreadNum <> -1 Then 110 _DebugSys_ProcNum[ThreadNum] = p pTryLayers[nTryLayers - 1]->debugProcNum-1165 _DebugSys_ProcNum[ThreadNum] = pTryLayer->debugProcNum-1 111 166 End If 112 167 #endif … … 118 173 End Sub 119 174 120 Sub _Throw( msg As String ) 121 _Throw() 175 Sub _ThrowWithParam( ex As Object ) 176 _Throw( ex ) 177 End Sub 178 179 Sub _ThrowNoneParam() 180 _Throw( Nothing ) 181 End Sub 182 183 Sub FinishFinally() 184 Dim pTryLayer = ppTryLayers[nTryLayers - 1] As *TryLayer 185 pTryLayer->FinishFinally() 122 186 End Sub 123 187 End Class
Note:
See TracChangeset
for help on using the changeset viewer.