source: trunk/Include/Classes/System/Threading/WaitHandle.ab@ 494

Last change on this file since 494 was 494, checked in by NoWest, 16 years ago

#ifndef~#define~#endifを除去

File size: 4.3 KB
RevLine 
[46]1' Classes/System/Threading/WaitHandle.ab
2
[261]3Namespace System
4Namespace Threading
5
[258]6Namespace Detail
7 TypeDef PFNSignalObjectAndWait = *Function(hObjectToSignal As HANDLE, hObjectToWaitOn As HANDLE, dwMilliseconds As DWord, bAlertable As DWord) As DWord
8End Namespace
9
[46]10Class WaitHandle
[381]11 Implements System.IDisposable
[46]12Public
[77]13 ' Properties
14' Const Function SafeWaitHandle() As SafeWaitHandle
15' Sub SafeWaitHandle(h As SafeWaitHandle)
[46]16
17 Const Virtual Function Handle() As HANDLE
18 Return h
19 End Function
20
21 Virtual Sub Handle(newHandle As HANDLE)
22 h = newHandle
23 End Sub
24
[77]25 ' Methods
[408]26 Virtual Sub WaitHandle()
27 End Sub
[77]28
29 Virtual Sub ~WaitHandle()
[408]30 This.Dispose()
[77]31 End Sub
32
[46]33 Virtual Sub Close()
[408]34 This.Dispose()
[46]35 End Sub
36
[388]37 Virtual Sub Dispose()
[261]38 Dim hDisposing = InterlockedExchangePointer(h, 0)
39 If hDisposing <> 0 Then
40 CloseHandle(hDisposing)
41 End If
42 End Sub
43
44 Function WaitOne() As Boolean
[47]45 Return WaitOne(INFINITE, FALSE)
46 End Function
[46]47
[388]48 Function WaitOne(millisecondsTimeout As Long, exitContext As Boolean) As Boolean
[47]49 Return WaitHandle.AfterWait(WaitForSingleObject(h, millisecondsTimeout As DWord), 1)
50 End Function
[46]51
[408]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
[47]57 Return WaitAll(count, handles, INFINITE, FALSE)
58 End Function
[46]59
[408]60 Static Function WaitAll(count As DWord, handles As *HANDLE, millisecondsTimeout As Long, exitContext As Boolean) As Boolean
[47]61 Return WaitHandle.AfterWait(WaitForMultipleObjects(count, handles, TRUE, millisecondsTimeout), count)
62 End Function
[46]63
[408]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
[46]67
[408]68 Static Function WaitAny(count As DWord, handles As *HANDLE) As Boolean
[47]69 Return WaitAny(count, handles, INFINITE, FALSE)
70 End Function
[46]71
[408]72 Static Function WaitAny(count As DWord, handles As *HANDLE, millisecondsTimeout As Long, exitContext As Boolean) As Boolean
[47]73 Return WaitHandle.AfterWait(WaitForMultipleObjects(count, handles, FALSE, millisecondsTimeout), count)
74 End Function
[46]75
[408]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)
78 End Function
79
[261]80 Static Function SignalAndWait(toSignal As WaitHandle, toWaitOn As WaitHandle) As Boolean
[47]81 Return SignalAndWait(toSignal, toWaitOn, INFINITE, FALSE)
82 End Function
[46]83
[408]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
[388]88 Static Function SignalAndWait(toSignal As WaitHandle, toWaitOn As WaitHandle, millisecondsTimeout As Long, exitContext As Boolean) As Boolean
[258]89 Dim pSignalObjectAndWait = GetProcAddress(GetModuleHandle("Kernel32.dll"), "SignalObjectAndWait") As Detail.PFNSignalObjectAndWait
[46]90 If pSignalObjectAndWait = 0 Then
[388]91 Throw New PlatformNotSupportedException("WaitHandle.SignalAndWait: This platform doesn't supoort this operation.")
[46]92 End If
[237]93 Return WaitHandle.AfterWait(pSignalObjectAndWait(toSignal.Handle, toWaitOn.Handle, millisecondsTimeout As DWord, FALSE), 1)
[47]94 End Function
[46]95
[408]96Public
97 Function WaitTimeout() As Long
98 Return WAIT_TIMEOUT
99 End Function
[46]100
101Protected
102 Static Const InvalidHandle = INVALID_HANDLE_VALUE As HANDLE
103
104Private
105 h As HANDLE
106
[261]107 Static Function AfterWait(ret As DWord, n As DWord) As Boolean
[46]108 Select Case ret
109 Case WAIT_TIMEOUT
[261]110 Return False
[46]111 Case WAIT_ABANDONED
112 ' Throw AbandonedMutexException
113 Debug
114 ExitThread(0)
115 'Case WAIT_FAILED
116 Case Else
[47]117 If WAIT_OBJECT_0 <= ret And ret < WAIT_OBJECT_0 + n Then
[261]118 Return True
[47]119 End If
[46]120 ' ObjectDisposedException?
121 Debug
122 ExitThread(0)
123 End Select
[58]124 End Function
[46]125End Class
126
[261]127End Namespace 'Threading
128End Namespace 'System
Note: See TracBrowser for help on using the repository browser.