- Timestamp:
- Aug 20, 2008, 3:37:44 AM (16 years ago)
- Location:
- trunk/ab5.0/ablib/src
- Files:
-
- 1 added
- 10 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/ab5.0/ablib/src/Classes/ActiveBasic/Windows/UI/Control.ab
r575 r599 123 123 .x, .y, .cx, .cy, .hwndParent, .hMenu, .hInstance, .lpCreateParams) 124 124 If hwnd = 0 Then 125 ActiveBasic.Windows.Throw ByWindowsError(GetLastError())125 ActiveBasic.Windows.ThrowWithLastError(GetLastError()) 126 126 End If 127 127 -
trunk/ab5.0/ablib/src/Classes/ActiveBasic/Windows/Windows.ab
r575 r599 110 110 111 111 /*! 112 @brief GetLastErrorのエラー値を基に例外を投げる。 113 @date 2008/07/13 112 @brief Windowsのエラー値を基に例外を投げる 114 113 @param[in] dwErrorCode Win32エラーコード 115 114 @throw WindowsException 常に投げられる。 116 @auther Egtra 115 @date 2008/07/13 116 @auther Egtra 117 117 */ 118 Sub Throw ByWindowsError(dwErrorCode As DWord)118 Sub ThrowWithErrorCode(dwErrorCode As DWord) 119 119 Throw New WindowsException(HRESULT_FROM_WIN32(dwErrorCode)) 120 120 End Sub 121 121 122 /*! 123 @brief 内部でGetLastErrorを呼んで、その値を基に例外を投げる。 124 @throw WindowsException 常に投げられる。 125 @date 2008/08/26 126 @auther Egtra 127 */ 128 Sub ThrowWithLastError() 129 ThrowWithErrorCode(GetLastError()) 130 End Sub 122 131 /*! 123 132 @brief HRESULT値を基に例外を投げる。 -
trunk/ab5.0/ablib/src/Classes/System/Threading/EventWaitHandle.ab
r494 r599 11 11 Class EventWaitHandle 12 12 Inherits System.Threading.WaitHandle 13 13 Private 14 Sub EventWaitHandle() 15 End Sub 14 16 Public 15 17 Sub EventWaitHandle (initialState As Boolean, mode As EventResetMode) … … 54 56 既存の名前付き同期イベントを開きます。 55 57 */ 56 Static Function OpenExisting(name As String) As WaitHandle 57 This.Handle(OpenEvent(EVENT_ALL_ACCESS,FALSE,ToTCStr(name))) 58 Static Function OpenExisting(name As String) As EventWaitHandle 59 If ActiveBasic.IsNothing(name) Then 60 Throw New ArgumentNullException("name") 61 Else If name.Length = 0 Then 62 Throw New ArgumentException("name") 63 End If 64 OpenExisting = New EventWaitHandle 65 Dim h = OpenEvent(EVENT_ALL_ACCESS, FALSE, ToTCStr(name)) 66 If h = 0 Then 67 IO.Detail.ThrowWinLastErrorIOException("OpenEvent failed.") 68 End If 69 OpenExisting.Handle = h 58 70 End Function 59 71 … … 95 107 WaitHandle から継承 96 108 Handle 97 SafeWaitHandle 109 SafeWaitHandle 98 110 */ 99 111 -
trunk/ab5.0/ablib/src/Classes/System/Threading/Exception.ab
r566 r599 1 Name Space System2 Name Space Threading1 Namespace System 2 Namespace Threading 3 3 4 4 Class AbandonedMutexException … … 104 104 End Class 105 105 106 End Name Space107 End Name Space106 End Namespace 107 End Namespace -
trunk/ab5.0/ablib/src/Classes/System/Threading/Thread.ab
r597 r599 460 460 461 461 Function FindThreadInfo(threadID As DWord) As *ThreadInfo 462 EnterCriticalSection(CriticalSection) 462 463 Dim i As Long 463 464 For i = 0 To ELM(ThreadNum) … … 467 468 End If 468 469 Next 470 LeaveCriticalSection(CriticalSection) 469 471 End Function 470 472 … … 476 478 Public 477 479 Function GetCurrentException() As ExceptionService 480 EnterCriticalSection(CriticalSection) 478 481 Dim dwNowThreadId = GetCurrentThreadId() 479 480 482 Dim i As Long 481 483 For i=0 To ELM(ThreadNum) 482 484 With collection[i] 483 485 If .thread.ThreadId = dwNowThreadId Then 484 Return .exception 486 GetCurrentException = .exception 487 Exit For 485 488 End If 486 489 End With 487 490 Next 488 489 OutputDebugString( Ex"カレントスレッドの取得に失敗\r\n" ) 490 Return Nothing 491 LeaveCriticalSection(CriticalSection) 492 If ActiveBasic.IsNothing(GetCurrentException) Then 493 OutputDebugString(Ex"カレントスレッドの取得に失敗\r\n") 494 End If 491 495 End Function 492 496 End Class -
trunk/ab5.0/ablib/src/Classes/System/Threading/WaitHandle.ab
r581 r599 24 24 25 25 ' Methods 26 VirtualSub WaitHandle()26 Sub WaitHandle() 27 27 End Sub 28 28 … … 43 43 44 44 Function WaitOne() As Boolean 45 Return WaitOne(INFINITE, FALSE) 46 End Function 47 48 Function WaitOne(millisecondsTimeout As Long, exitContext As Boolean) As Boolean 49 Return WaitHandle.AfterWait(WaitForSingleObject(h, millisecondsTimeout As DWord), 1) 50 End Function 51 52 Function WaitOne(timeout As System.TimeSpan, exitContext As Boolean) As Boolean 53 Return WaitHandle.AfterWait(WaitForSingleObject(h, timeout.TotalMilliseconds() As DWord), 1) 54 End Function 55 56 Static Function WaitAll(count As DWord, handles As *HANDLE) As Boolean 57 Return WaitAll(count, handles, INFINITE, FALSE) 58 End Function 59 60 Static Function WaitAll(count As DWord, handles As *HANDLE, millisecondsTimeout As Long, exitContext As Boolean) As Boolean 61 Return WaitHandle.AfterWait(WaitForMultipleObjects(count, handles, TRUE, millisecondsTimeout), count) 62 End Function 63 64 Static Function WaitAll(count As DWord, handles As *HANDLE, timeout As System.TimeSpan, exitContext As Boolean) As Boolean 65 Return WaitHandle.AfterWait(WaitForMultipleObjects(count, handles, TRUE, timeout.TotalMilliseconds() As DWord), count) 66 End Function 67 68 Static Function WaitAny(count As DWord, handles As *HANDLE) As Boolean 69 Return WaitAny(count, handles, INFINITE, FALSE) 70 End Function 71 72 Static Function WaitAny(count As DWord, handles As *HANDLE, millisecondsTimeout As Long, exitContext As Boolean) As Boolean 73 Return WaitHandle.AfterWait(WaitForMultipleObjects(count, handles, FALSE, millisecondsTimeout), count) 74 End Function 75 76 Static Function WaitAny(count As DWord, handles As *HANDLE, timeout As System.TimeSpan, exitContext As Boolean) As Boolean 77 Return WaitHandle.AfterWait(WaitForMultipleObjects(count, handles, FALSE, timeout.TotalMilliseconds() As DWord), count) 45 Return WaitOne(INFINITE As DWord) 46 End Function 47 48 Function WaitOne(millisecondsTimeout As DWord) As Boolean 49 If h = 0 Then 50 Throw New ObjectDisposedException("WaitHandle.WaitOne") 51 End If 52 Return afterWait(WaitForSingleObject(h, millisecondsTimeout As DWord), 1) 53 End Function 54 55 Function WaitOne(millisecondsTimeout As Long) As Boolean 56 ThrowIfInvalidLongValue(millisecondsTimeout) 57 Return WaitOne(millisecondsTimeout As DWord) 58 End Function 59 60 Function WaitOne(timeout As System.TimeSpan) As Boolean 61 Return WaitOne(timeout.TotalMilliseconds() As Long) 62 End Function 63 64 Static Function WaitAll(handles As Collections.Generic.IList<WaitHandle>) As Boolean 65 Return waitImpl(handles, TRUE, INFINITE As DWord) 66 End Function 67 68 Static Function WaitAll(handles As Collections.Generic.IList<WaitHandle>, millisecondsTimeout As Long) As Boolean 69 ThrowIfInvalidLongValue(millisecondsTimeout) 70 Return waitImpl(handles, TRUE, millisecondsTimeout As DWord) 71 End Function 72 73 Static Function WaitAll(handles As Collections.Generic.IList<WaitHandle>, millisecondsTimeout As DWord) As Boolean 74 Return waitImpl(handles, TRUE, millisecondsTimeout) 75 End Function 76 77 Static Function WaitAll(handles As Collections.Generic.IList<WaitHandle>, timeout As System.TimeSpan) As Boolean 78 Return WaitAny(handles, timeout.TotalMilliseconds() As Long) 79 End Function 80 81 Static Function WaitAny(handles As Collections.Generic.IList<WaitHandle>) As Boolean 82 Return waitImpl(handles, FALSE, INFINITE As DWord) 83 End Function 84 85 Static Function WaitAny(handles As Collections.Generic.IList<WaitHandle>, millisecondsTimeout As Long) As Boolean 86 ThrowIfInvalidLongValue(millisecondsTimeout) 87 Return waitImpl(handles, FALSE, millisecondsTimeout As DWord) 88 End Function 89 90 Static Function WaitAny(handles As Collections.Generic.IList<WaitHandle>, millisecondsTimeout As DWord) As Boolean 91 Return waitImpl(handles, FALSE, millisecondsTimeout) 92 End Function 93 94 Static Function WaitAny(handles As Collections.Generic.IList<WaitHandle>, timeout As System.TimeSpan) As Boolean 95 Return WaitAny(handles, timeout.TotalMilliseconds() As Long) 78 96 End Function 79 97 80 98 Static Function SignalAndWait(toSignal As WaitHandle, toWaitOn As WaitHandle) As Boolean 81 Return SignalAndWait(toSignal, toWaitOn, INFINITE, FALSE) 82 End Function 83 84 Static Function SignalAndWait (toSignal As WaitHandle, toWaitOn As WaitHandle, timeout As System.TimeSpan, exitContext As Boolean) As Boolean 85 Return SignalAndWait(toSignal, toWaitOn, timeout.TotalMilliseconds() As Long, FALSE) 86 End Function 87 88 Static Function SignalAndWait(toSignal As WaitHandle, toWaitOn As WaitHandle, millisecondsTimeout As Long, exitContext As Boolean) As Boolean 99 Return SignalAndWait(toSignal, toWaitOn, INFINITE) 100 End Function 101 102 Static Function SignalAndWait(toSignal As WaitHandle, toWaitOn As WaitHandle, timeout As System.TimeSpan) As Boolean 103 Return SignalAndWait(toSignal, toWaitOn, timeout.TotalMilliseconds() As Long) 104 End Function 105 106 Static Function SignalAndWait(toSignal As WaitHandle, toWaitOn As WaitHandle, timeout As Long) As Boolean 107 Return SignalAndWait(toSignal, toWaitOn, timeout As DWord) 108 End Function 109 110 Static Function SignalAndWait(toSignal As WaitHandle, toWaitOn As WaitHandle, millisecondsTimeout As DWord) As Boolean 89 111 Dim pSignalObjectAndWait = GetProcAddress(GetModuleHandle("Kernel32.dll"), ToMBStr("SignalObjectAndWait")) As Detail.PFNSignalObjectAndWait 90 112 If pSignalObjectAndWait = 0 Then 91 113 Throw New PlatformNotSupportedException("WaitHandle.SignalAndWait: This platform doesn't supoort this operation.") 92 114 End If 93 Return WaitHandle.AfterWait(pSignalObjectAndWait(toSignal.Handle, toWaitOn.Handle, millisecondsTimeout As DWord, FALSE), 1) 94 End Function 95 96 Public 97 Function WaitTimeout() As Long 98 Return WAIT_TIMEOUT 99 End Function 115 Return afterWait(pSignalObjectAndWait(toSignal.Handle, toWaitOn.Handle, millisecondsTimeout As DWord, FALSE), 1) 116 End Function 117 118 Static Const WaitTimeout = WAIT_TIMEOUT 100 119 101 120 Protected … … 105 124 h As HANDLE 106 125 107 Static Function AfterWait(ret As DWord, n As DWord) As Boolean 126 /*! 127 @brief WaitAll/WaitAnyの実装 128 @param[in] handles 待機ハンドル 129 @param[in] waitAll WaitAllならTRUE、WaitAnyならFALSE 130 @param[in] millisecondsTimeout タイムアウトまでの時間。-1 As DWordなら無限に待ち続ける。 131 @return シグナルが発生したらTrue、タイムアウトになったらFalse。 132 @date 2008/08/27 133 @auther Egtra 134 */ 135 Static Function waitImpl(handles As Collections.Generic.IList<WaitHandle>, waitAll As BOOL, millisecondsTimeout As DWord) As Boolean 136 ' If ActiveBasic.IsNothing(handles) Then 137 ' Throw New ArgumentNullException("handles") 138 ' End If 139 Dim count = handles.Count 140 If count > MAXIMUM_WAIT_OBJECTS Then 141 Throw New InvalidOperationException("handles.Count > MAXIMUM_WAIT_OBJECTS") 142 End If 143 Return afterWait(WaitForMultipleObjects(count, ToArrayOfHANDLE(handles), waitAll, millisecondsTimeout), count) 144 End Function 145 146 /*! 147 @brief 待機が終了した後の処理を行う。 148 @param[in] ret 待機関数の戻り値 149 @param[in] n 待機させたハンドルの数 150 @return シグナルが発生したらTrue、タイムアウトになったらFalse。 151 @auther Egtra 152 */ 153 Static Function afterWait(ret As DWord, n As DWord) As Boolean 108 154 Select Case ret 109 155 Case WAIT_TIMEOUT 110 156 Return False 111 157 Case WAIT_ABANDONED 112 ' Throw AbandonedMutexException158 Throw New AbandonedMutexException 113 159 Debug 114 160 ExitThread(0) 115 'Case WAIT_FAILED 161 Case WAIT_FAILED 162 ActiveBasic.Windows.ThrowWithLastError() 116 163 Case Else 117 164 If WAIT_OBJECT_0 <= ret And ret < WAIT_OBJECT_0 + n Then … … 123 170 End Select 124 171 End Function 172 173 /*! 174 @brief WaitHandleのリストをHANDLE配列にする。 175 @param[in] handles 変換元 176 @return 変換済みの配列の要素を指すポインタ 177 @date 2008/08/27 178 @auther Egtra 179 */ 180 Static Function ToArrayOfHANDLE(handles As Collections.Generic.IList<WaitHandle>) As *HANDLE 181 Dim count = handles.Count 182 ToArrayOfHANDLE = GC_malloc(count * SizeOf(HANDLE)) 183 Dim i As Long 184 For i = 0 To ELM(count) 185 ToArrayOfHANDLE[i] = handles.Item[i].h 186 Next 187 End Function 188 189 /*! 190 @brief Long値が0以上か-1でない場合、例外を投げる。 191 @param[in] x テストする値 192 @throw ArgumentOutOfRangeException -1未満の値のとき 193 @date 2008/08/27 194 @auther Egtra 195 */ 196 Static Sub ThrowIfInvalidLongValue(x As Long) 197 If x < -1 Then 198 Throw New ArgumentOutOfRangeException("millisecondsTimeout") 199 End If 200 End Sub 125 201 End Class 126 202 -
trunk/ab5.0/ablib/src/Classes/index.ab
r598 r599 92 92 #require "./System/Threading/AutoResetEvent.ab" 93 93 #require "./System/Threading/EventWaitHandle.ab" 94 #require "./System/Threading/Exception.ab" 94 95 #require "./System/Threading/ManualResetEvent.ab" 95 96 #require "./System/Threading/Mutex.ab" 96 97 #require "./System/Threading/Semaphore.ab" 97 98 #require "./System/Threading/Thread.ab" 99 #require "./System/Threading/ThreadPool.ab" 98 100 #require "./System/Threading/Timeout.ab" 99 101 #require "./System/Threading/WaitHandle.ab" -
trunk/ab5.0/ablib/src/WinNT.ab
r497 r599 5535 5535 Const WT_TRANSFER_IMPERSONATION = &h00000100 5536 5536 'Const WT_SET_MAX_THREADPOOL_THREADS(Flags, Limit) ((Flags) Or= (Limit)<<16) 5537 TypeDef WAITORTIMERCALLBACKFUNC = *Sub(p As VoidPtr, b As B oolean)5537 TypeDef WAITORTIMERCALLBACKFUNC = *Sub(p As VoidPtr, b As BOOLEAN) 5538 5538 TypeDef WORKERCALLBACKFUNC = *Sub(p As VoidPtr) 5539 5539 TypeDef APC_CALLBACK_FUNCTION = *Sub(dw AS DWord, p1 As VoidPtr, p2 As VoidPtr) -
trunk/ab5.0/ablib/src/api_system.sbp
r562 r599 555 555 End Type 556 556 Declare Function GetFileInformationByHandle Lib "kernel32" ( 557 558 557 ByVal hFile As HANDLE, 558 ByRef FileInformation As BY_HANDLE_FILE_INFORMATION 559 559 ) As BOOL 560 560 Declare Function GetFileSize Lib "kernel32" (hFile As HANDLE, pFileSizeHigh As *DWord) As DWord 561 'Declare Function GetFileSizeEx Lib "kernel32" (hFile As HANDLE, pFileSizeHigh As *QWord) As B oolean561 'Declare Function GetFileSizeEx Lib "kernel32" (hFile As HANDLE, pFileSizeHigh As *QWord) As BOOL 562 562 Declare Function GetFileTime Lib "kernel32" (hFile As HANDLE, ByRef lpCreationTime As FILETIME, ByRef lpLastAccessTime As FILETIME, ByRef lpLastWriteTime As FILETIME) As BOOL 563 563 … … 805 805 Const FILE_CURRENT = 1 806 806 Const FILE_END = 2 807 Declare Function SetFilePointer Lib "kernel32" (hFile As HANDLE, lDistanceToMove As Long, lpDistanceToMoveHigh As DWordPtr, dwMoveMethod As DWord) As DWord807 Declare Function SetFilePointer Lib "kernel32" (hFile As HANDLE, lDistanceToMove As Long, lpDistanceToMoveHigh As *Long, dwMoveMethod As DWord) As DWord 808 808 809 809 Declare Function SetFileTime Lib "kernel32" (hFile As HANDLE, ByRef lpCreationTime As FILETIME, ByRef lpLastAccessTime As FILETIME, ByRef lpLastWriteTime As FILETIME) As BOOL … … 975 975 Const MAKEINTATOM(i) = (i As Word As ULONG_PTR As LPTSTR) 976 976 Const INVALID_ATOM = 0 As ATOM 977 978 '#if _WIN32_WINNT > &h0500 979 TypeDef WAITORTIMERCALLBACK = WAITORTIMERCALLBACKFUNC 980 981 '#endif -
trunk/ab5.0/ablib/src/system/exception.ab
r464 r599 54 54 End If 55 55 56 If Object.ReferenceEquals( ex, Nothing) Then56 If ActiveBasic.IsNothing( ex ) Then 57 57 ' パラメータなしのとき 58 58 If paramName[0] = 0 Then
Note:
See TracChangeset
for help on using the changeset viewer.