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

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

Prompt.sbp内を名前空間に入れた。EnvironmentのMachineName, UserName, GetFolderPathを実装。

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