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

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

#_fullcompileで検出されたエラーの修正(明らかに判るもののみ)

File size: 3.5 KB
RevLine 
[46]1' Classes/System/Threading/WaitHandle.ab
2
3#ifndef __SYSTEM_THREADING_WAITHANDLE_AB__
4#define __SYSTEM_THREADING_WAITHANDLE_AB__
5
6Class WaitHandle
7Public
[77]8 ' Properties
9' Const Function SafeWaitHandle() As SafeWaitHandle
10' Sub SafeWaitHandle(h As SafeWaitHandle)
[46]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
[77]20 ' Methods
21
22 Virtual Sub ~WaitHandle()
[119]23 CloseHandle(h)
[77]24 End Sub
25
[46]26 Virtual Sub Close()
27 CloseHandle(h)
28 End Sub
29
[47]30 Function WaitOne() As BOOL
31 Return WaitOne(INFINITE, FALSE)
32 End Function
[46]33
[47]34 Function WaitOne(millisecondsTimeout As Long, exitContext As BOOL) As BOOL
35 Return WaitHandle.AfterWait(WaitForSingleObject(h, millisecondsTimeout As DWord), 1)
36 End Function
[46]37
[47]38' Function WaitOne(timeout As TimeSpan, exitContext As BOOL) As BOOL
[46]39/*
[47]40 Static Function WaitAll(count As DWord, handles As *HANDLE) As BOOL
41 Return WaitAll(count, handles, INFINITE, FALSE)
42 End Function
[46]43
[47]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
[46]47
[47]48' Static Function WaitAll(timeout As TimeSpan, handles As *HANDLE, millisecondsTimeout As Long, exitContext As BOOL) As BOOL
[46]49
[47]50 Static Function WaitAny(count As DWord, handles As *HANDLE) As BOOL
51 Return WaitAny(count, handles, INFINITE, FALSE)
52 End Function
[46]53
[47]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
[46]57
[47]58' Static Function WaitAny(timeout As TimeSpan, handles As *HANDLE, millisecondsTimeout As Long, exitContext As BOOL) As BOOL
[46]59*/
[47]60 Static Function SignalAndWait(ByRef toSignal As WaitHandle, ByRef toWaitOn As WaitHandle) As BOOL
61 Return SignalAndWait(toSignal, toWaitOn, INFINITE, FALSE)
62 End Function
[46]63
[47]64 Static Function SignalAndWait(ByRef toSignal As WaitHandle, ByRef toWaitOn As WaitHandle, millisecondsTimeout As Long, exitContext As BOOL) As BOOL
[237]65 TypeDef PFNSignalObjectAndWait = *Function(hObjectToSignal As HANDLE, hObjectToWaitOn As HANDLE, dwMilliseconds As DWord, bAlertable As DWord) As DWord
66 Dim pSignalObjectAndWait = GetProcAddress(GetModuleHandle("Kernel32.dll"), "SignalObjectAndWait") As PFNSignalObjectAndWait
[46]67 If pSignalObjectAndWait = 0 Then
68 ' PlatformNotSupportedException
69 Debug
[237]70 ExitThread(-1)
[46]71 End If
[237]72 Return WaitHandle.AfterWait(pSignalObjectAndWait(toSignal.Handle, toWaitOn.Handle, millisecondsTimeout As DWord, FALSE), 1)
[47]73 End Function
[46]74
[47]75' Static Function SignalAndWait(ByRef toSignal As WaitHandle, ByRef toWaitOn As WaitHandle, timeout As TimeSpan, exitContext As BOOL) As BOOL
[46]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
[47]87 Static Function AfterWait(ret As DWord, n As DWord) As BOOL
[46]88 Select Case ret
89 Case WAIT_TIMEOUT
[47]90 Return FALSE
[46]91 Case WAIT_ABANDONED
92 ' Throw AbandonedMutexException
93 Debug
94 ExitThread(0)
95 'Case WAIT_FAILED
96 Case Else
[47]97 If WAIT_OBJECT_0 <= ret And ret < WAIT_OBJECT_0 + n Then
98 Return TRUE
99 End If
[46]100 ' ObjectDisposedException?
101 Debug
102 ExitThread(0)
103 End Select
[58]104 End Function
[46]105End Class
106
107#endif '__SYSTEM_THREADING_WAITHANDLE_AB__
Note: See TracBrowser for help on using the repository browser.