Ignore:
Timestamp:
Jan 12, 2007, 3:21:30 AM (18 years ago)
Author:
dai
Message:

例外処理用に必要なコードを追加。
空間統括ファイル(index.ab)を作成。
その他クラスの調整。

Location:
Include/Classes/System/Threading
Files:
1 added
2 edited

Legend:

Unmodified
Added
Removed
  • Include/Classes/System/Threading/Thread.ab

    r42 r58  
    11'threading.sbp
    22
     3
     4'--------------------------------------------------------------------
     5' スレッドの優先順位
     6'--------------------------------------------------------------------
    37Enum ThreadPriority
    48    Highest =      2
     
    1115TypeDef PTHREAD_START_ROUTINE = *Function(args As VoidPtr) As DWord
    1216
     17
     18'--------------------------------------------------------------------
     19' スレッド クラス
     20'--------------------------------------------------------------------
    1321Class Thread
    1422    m_hThread As HANDLE
     
    1927    m_fp As PTHREAD_START_ROUTINE
    2028    m_args As VoidPtr
     29
    2130Public
    2231    Sub Thread()
     
    137146        Return GetThreadContext(m_hThread,Context)
    138147    End Function
     148    Function __SetContext(ByRef Context As CONTEXT) As BOOL
     149        Return SetThreadContext(m_hThread,Context)
     150    End Function
    139151
    140152
     
    147159
    148160
    149 'すべてのスレッドの管理
     161'--------------------------------------------------------------------
     162' すべてのスレッドの管理
     163'--------------------------------------------------------------------
     164' TODO: このクラスをシングルトンにする
    150165Class _System_CThreadCollection
    151166Public
     
    159174        ppobj_Thread=HeapAlloc(_System_hProcessHeap,0,1)
    160175        pStackBase=HeapAlloc(_System_hProcessHeap,0,1)
     176        ppException=HeapAlloc(_System_hProcessHeap,0,1)
    161177        ThreadNum=0
    162178
     
    175191        pStackBase=0
    176192
     193        HeapFree(_System_hProcessHeap,0,ppException)
     194        ppException = 0
     195
    177196        ThreadNum=0
    178197
     
    185204        EnterCriticalSection(CriticalSection)
    186205
     206            'スレッドオブジェクトを生成
    187207            Dim pobj_NewThread As *Thread
    188208            pobj_NewThread=New Thread(obj_Thread)
    189209
     210            '例外処理管理用オブジェクトを生成
     211            Dim pException As *ExceptionService
     212            pException = New ExceptionService
     213
    190214            Dim i As Long
    191215            For i=0 To ELM(ThreadNum)
    192                 If ppobj_Thread[i]=0 Then
    193                     ppobj_Thread[i]=pobj_NewThread
    194                     pStackBase[i]=NowSp
     216                If ppobj_Thread[i] = 0 Then
     217                    ppobj_Thread[i] = pobj_NewThread
     218                    pStackBase[i] = NowSp
     219                    ppException[i] = pException
    195220                    Exit For
    196221                End If
    197222            Next
    198223
    199             If i=ThreadNum Then
     224            If i = ThreadNum Then
    200225                ppobj_Thread=HeapReAlloc(_System_hProcessHeap,0,ppobj_Thread,(ThreadNum+1)*SizeOf(*Thread))
    201226                ppobj_Thread[ThreadNum]=pobj_NewThread
    202227                pStackBase=HeapReAlloc(_System_hProcessHeap,0,pStackBase,(ThreadNum+1)*SizeOf(LONG_PTR))
    203228                pStackBase[ThreadNum]=NowSp
     229                ppException=HeapReAlloc(_System_hProcessHeap,0,ppException,(ThreadNum+1)*SizeOf(*ExceptionService))
     230                ppException[ThreadNum]=pException
    204231                ThreadNum++
    205232            End If
     
    242269    End Sub
    243270
    244 
     271    'カレントスレッドを取得
    245272    Function CurrentThread(ByRef obj_Thread As Thread) As BOOL
    246273        Dim dwNowThreadId As DWord
     
    257284        Return 0
    258285    End Function
     286
     287
     288Private
     289    '------------------------------------------
     290    ' スレッド固有の例外処理制御
     291    '------------------------------------------
     292    ppException As **ExceptionService
     293
     294Public
     295    Function GetCurrentException() As *ExceptionService
     296        Dim dwNowThreadId As DWord
     297        dwNowThreadId=GetCurrentThreadId()
     298
     299        Dim i As Long
     300        For i=0 To ELM(ThreadNum)
     301            If ppobj_Thread[i]->ThreadId=dwNowThreadId Then
     302                Return ppException[i]
     303            End If
     304        Next
     305
     306        Return NULL
     307    End Function
    259308End Class
    260309Dim _System_pobj_AllThreads As *_System_CThreadCollection
  • Include/Classes/System/Threading/WaitHandle.ab

    r47 r58  
    9999                ExitThread(0)
    100100        End Select
    101     End Sub
     101    End Function
    102102End Class
    103103
Note: See TracChangeset for help on using the changeset viewer.