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

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

Unicode (#50) 前準備
Byte→Char (#51) 型名は殆ど完了、ただし中身までは手を付けていないものが多い

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