source: trunk/Include/Classes/ActiveBasic/Windows/CriticalSection.ab@ 335

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

SPrintF関連の追加。関数FloatToChars, FormatFloatE, FormatIntegerUと列挙体FormatFlags。

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