Last change
on this file since 324 was 303, checked in by イグトランス (egtra), 18 years ago |
フルコンパイルでのミスあぶり出し。註:修正は全て@300や@301以前に行われた。
|
File size:
1.4 KB
|
Rev | Line | |
---|
[261] | 1 | 'Classes/ActiveBasic/Windows/CriticalSection.ab
|
---|
| 2 |
|
---|
| 3 | #require <Classes/System/index.ab>
|
---|
| 4 |
|
---|
| 5 | Namespace ActiveBasic
|
---|
| 6 | Namespace Windows
|
---|
| 7 |
|
---|
[269] | 8 | Namespace Detail
|
---|
[303] | 9 | Const InterlockedExchangeAnyPointer(p, x) = InterlockedExchangePointer(ByVal VarPtr(p) As *VoidPtr, x)
|
---|
[269] | 10 | End Namespace
|
---|
| 11 |
|
---|
[261] | 12 | Class CriticalSection
|
---|
[269] | 13 | ' Inherits System.IDisposable
|
---|
[261] | 14 | Public
|
---|
| 15 | Sub CriticalSection()
|
---|
| 16 | disposed = 0
|
---|
| 17 | InitializeCriticalSection(cs)
|
---|
| 18 | End Sub
|
---|
| 19 |
|
---|
| 20 | Sub ~CriticalSection()
|
---|
| 21 | Dispose()
|
---|
| 22 | End Sub
|
---|
| 23 |
|
---|
[269] | 24 | /*Override*/ Sub Dispose()
|
---|
[261] | 25 | If InterlockedIncrement(disposed) = 0 Then
|
---|
| 26 | DeleteCriticalSection(cs)
|
---|
| 27 | End If
|
---|
| 28 | End Sub
|
---|
| 29 |
|
---|
[269] | 30 | Function Enter() As ActiveBasic.Windows.CriticalSectionLock
|
---|
[261] | 31 | Return New CriticalSectionLock(cs)
|
---|
| 32 | End Function
|
---|
| 33 | Private
|
---|
| 34 | cs As CRITICAL_SECTION
|
---|
| 35 | disposed As Long
|
---|
| 36 | End Class
|
---|
| 37 |
|
---|
| 38 | Class CriticalSectionLock
|
---|
[269] | 39 | ' Inherits System.IDisposable
|
---|
[261] | 40 | Public
|
---|
| 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 |
|
---|
[269] | 54 | /*Override*/ Sub Dispose()
|
---|
[303] | 55 | ' Dim p = ActiveBasic.Windows.Detail.InterlockedExchangeAnyPointer(pcs, 0)
|
---|
| 56 | Dim p = InterlockedExchangePointer(pcs As VoidPtr, 0) As *CRITICAL_SECTION
|
---|
| 57 | If p <> 0 Then
|
---|
| 58 | LeaveCriticalSection(ByVal p)
|
---|
[261] | 59 | End If
|
---|
| 60 | End Sub
|
---|
| 61 | Private
|
---|
| 62 | pcs As *CRITICAL_SECTION
|
---|
| 63 | End Class
|
---|
| 64 |
|
---|
| 65 | End Namespace 'Windows
|
---|
| 66 | End Namespace 'ActiveBasic
|
---|
Note:
See
TracBrowser
for help on using the repository browser.