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

Last change on this file since 388 was 388, checked in by イグトランス (egtra), 16 years ago

Stringなどで例外を投げるようにした。
#147の解決。
CType ASCII文字判定関数群の追加。

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