source: Include/Classes/ActiveBasic/Windows/CriticalSection.ab@ 261

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

CriticalSection, CriticalSectionLockの追加

File size: 1.1 KB
Line 
1'Classes/ActiveBasic/Windows/CriticalSection.ab
2
3#require <Classes/System/index.ab>
4
5Namespace ActiveBasic
6Namespace Windows
7
8Class CriticalSection
9 Inherits System.IDisposable
10Public
11 Sub CriticalSection()
12 disposed = 0
13 InitializeCriticalSection(cs)
14 End Sub
15
16 Sub ~CriticalSection()
17 Dispose()
18 End Sub
19
20 Override Sub Dispose()
21 If InterlockedIncrement(disposed) = 0 Then
22 DeleteCriticalSection(cs)
23 End If
24 End Sub
25
26 Function Enter() As CriticalSectionLock
27 Return New CriticalSectionLock(cs)
28 End Function
29Private
30 cs As CRITICAL_SECTION
31 disposed As Long
32End Class
33
34Class CriticalSectionLock
35 Inherits System.IDisposable
36Public
37 Sub CriticalSectionLock(ByRef cs As CRITICAL_SECTION)
38 pcs = VarPtr(cs)
39 EnterCriticalSection(cs)
40 End Sub
41
42 Sub ~CriticalSectionLock()
43 Dispose()
44 End Sub
45
46 Sub Leave()
47 Dispose()
48 End Sub
49
50 Override Sub Dispose()
51 Dim p = InterlockedExchangePointer(ByVal VarPtr(pcs), 0)
52 If p <> 0 Then
53 LeaveCriticalSection(ByVal p)
54 End If
55 End Sub
56Private
57 pcs As *CRITICAL_SECTION
58End Class
59
60End Namespace 'Windows
61End Namespace 'ActiveBasic
Note: See TracBrowser for help on using the repository browser.