source: trunk/Include/Classes/System/Threading/WaitHandle.ab@ 388

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

Stringなどで例外を投げるようにした。
#147の解決。
CType ASCII文字判定関数群の追加。

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