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

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

最低限の実装

File size: 3.1 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 Sub WaitOne()
28 WaitOne(INFINITE, FALSE)
29 End Sub
30
31 Sub WaitOne(millisecondsTimeout As Long, exitContext As BOOL)
32 WaitHandle.ExitThreadIfWaitIsFailed(WaitForSingleObject(h, millisecondsTimeout As DWord))
33 End Sub
34
35' Sub WaitOne(timeout As TimeSpan, exitContext As BOOL)
36/*
37 Static Sub WaitAll(count As DWord, handles As *HANDLE)
38 WaitAll(count, handles, INFINITE, FALSE)
39 End Sub
40
41 Static Sub WaitAll(count As DWord, handles As *HANDLE, millisecondsTimeout As Long, exitContext As BOOL)
42 WaitHandle.ExitThreadIfWaitIsFailed(WaitForMultipleObjects(count, handles, TRUE, millisecondsTimeout))
43 End Sub
44
45' Static Sub WaitAll(timeout As TimeSpan, handles As *HANDLE, millisecondsTimeout As Long, exitContext As BOOL)
46
47 Static Sub WaitAny(count As DWord, handles As *HANDLE)
48 WaitAny(count, handles, INFINITE, FALSE)
49 End Sub
50
51 Static Sub WaitAny(count As DWord, handles As *HANDLE, millisecondsTimeout As Long, exitContext As BOOL)
52 WaitHandle.ExitThreadIfWaitIsFailed(WaitForMultipleObjects(count, handles, FALSE, millisecondsTimeout))
53 End Sub
54
55' Static Sub WaitAny(timeout As TimeSpan, handles As *HANDLE, millisecondsTimeout As Long, exitContext As BOOL)
56*/
57 Static Sub SignalAndWait(ByRef toSignal As WaitHandle, ByRef toWaitOn As WaitHandle)
58 SignalAndWait(toSignal, toWaitOn, INFINITE, FALSE)
59 End Sub
60
61 Static Sub SignalAndWait(ByRef toSignal As WaitHandle, ByRef toWaitOn As WaitHandle, millisecondsTimeout As Long, exitContext 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 ExitThreadIfWaitIsFailed(pSignalAndWait(toSignal.Handle, toWaitOn.Handle, millisecondsTimeout As DWord))
70 End Sub
71
72' Static Sub SignalAndWait(ByRef toSignal As WaitHandle, ByRef toWaitOn As WaitHandle, timeout As TimeSpan, exitContext 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 Sub ExitThreadIfWaitIsFailed(ret As DWord)
85 Select Case ret
86 Case WAIT_OBJECT_0
87 Exit Sub
88 Case WAIT_TIMEOUT
89 Exit Sub
90 Case WAIT_ABANDONED
91 ' Throw AbandonedMutexException
92 Debug
93 ExitThread(0)
94 'Case WAIT_FAILED
95 Case Else
96 ' ObjectDisposedException?
97 Debug
98 ExitThread(0)
99 End Select
100 End Sub
101End Class
102
103#endif '__SYSTEM_THREADING_WAITHANDLE_AB__
Note: See TracBrowser for help on using the repository browser.