source: Include/Classes/System/Threading/WaitHandle.ab@ 51

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

戻り値型の間違い

File size: 3.3 KB
Line 
1' Classes/System/Threading/WaitHandle.ab
2
3#ifndef __SYSTEM_THREADING_WAITHANDLE_AB__
4#define __SYSTEM_THREADING_WAITHANDLE_AB__
5
6Class WaitHandle
7Public
8 Virtual Sub ~WaitHandle()
9 Close()
10 End Sub
11
12 ' Const Function SafeWaitHandle() As SafeWaitHandle
13 ' Sub SafeWaitHandle(h As SafeWaitHandle)
14
15 Const Virtual Function Handle() As HANDLE
16 Return h
17 End Function
18
19 Virtual Sub Handle(newHandle As HANDLE)
20 h = newHandle
21 End Sub
22
23 Virtual Sub Close()
24 CloseHandle(h)
25 End Sub
26
27 Function WaitOne() As BOOL
28 Return WaitOne(INFINITE, FALSE)
29 End Function
30
31 Function WaitOne(millisecondsTimeout As Long, exitContext As BOOL) As BOOL
32 Return WaitHandle.AfterWait(WaitForSingleObject(h, millisecondsTimeout As DWord), 1)
33 End Function
34
35' Function WaitOne(timeout As TimeSpan, exitContext As BOOL) As BOOL
36/*
37 Static Function WaitAll(count As DWord, handles As *HANDLE) As BOOL
38 Return WaitAll(count, handles, INFINITE, FALSE)
39 End Function
40
41 Static Function WaitAll(count As DWord, handles As *HANDLE, millisecondsTimeout As Long, exitContext As BOOL) As BOOL
42 Return WaitHandle.AfterWait(WaitForMultipleObjects(count, handles, TRUE, millisecondsTimeout), count)
43 End Function
44
45' Static Function WaitAll(timeout As TimeSpan, handles As *HANDLE, millisecondsTimeout As Long, exitContext As BOOL) As BOOL
46
47 Static Function WaitAny(count As DWord, handles As *HANDLE) As BOOL
48 Return WaitAny(count, handles, INFINITE, FALSE)
49 End Function
50
51 Static Function WaitAny(count As DWord, handles As *HANDLE, millisecondsTimeout As Long, exitContext As BOOL) As BOOL
52 Return WaitHandle.AfterWait(WaitForMultipleObjects(count, handles, FALSE, millisecondsTimeout), count)
53 End Function
54
55' Static Function WaitAny(timeout As TimeSpan, handles As *HANDLE, millisecondsTimeout As Long, exitContext As BOOL) As BOOL
56*/
57 Static Function SignalAndWait(ByRef toSignal As WaitHandle, ByRef toWaitOn As WaitHandle) As BOOL
58 Return SignalAndWait(toSignal, toWaitOn, INFINITE, FALSE)
59 End Function
60
61 Static Function SignalAndWait(ByRef toSignal As WaitHandle, ByRef toWaitOn As WaitHandle, millisecondsTimeout As Long, exitContext As BOOL) As BOOL
62 Dim pSignalObjectAndWait = GetProcAddress(GetModuleHandle("Kernel32.dll"), "SignalObjectAndWait") _
63 As *Function(hObjectToSignal As HANDLE, hObjectToWaitOn As HANDLE, dwMilliseconds As DWord, bAlertable As DWord) As DWord
64 If pSignalObjectAndWait = 0 Then
65 ' PlatformNotSupportedException
66 Debug
67 ExitThread(0)
68 End If
69 Return AfterWait(pSignalAndWait(toSignal.Handle, toWaitOn.Handle, millisecondsTimeout As DWord), 1)
70 End Function
71
72' Static Function SignalAndWait(ByRef toSignal As WaitHandle, ByRef toWaitOn As WaitHandle, timeout As TimeSpan, exitContext As BOOL) As BOOL
73
74' Protected
75 Sub WaitHandle()
76 End Sub
77
78Protected
79 Static Const InvalidHandle = INVALID_HANDLE_VALUE As HANDLE
80
81Private
82 h As HANDLE
83
84 Static Function AfterWait(ret As DWord, n As DWord) As BOOL
85 Select Case ret
86 Case WAIT_TIMEOUT
87 Return FALSE
88 Case WAIT_ABANDONED
89 ' Throw AbandonedMutexException
90 Debug
91 ExitThread(0)
92 'Case WAIT_FAILED
93 Case Else
94 If WAIT_OBJECT_0 <= ret And ret < WAIT_OBJECT_0 + n Then
95 Return TRUE
96 End If
97 ' ObjectDisposedException?
98 Debug
99 ExitThread(0)
100 End Select
101 End Sub
102End Class
103
104#endif '__SYSTEM_THREADING_WAITHANDLE_AB__
Note: See TracBrowser for help on using the repository browser.