Last change
on this file since 461 was 439, checked in by dai, 17 years ago |
InterlockedExchangePointer関数の第一引数に意図するポインタ値が渡っていなかったため、修正した。
|
File size:
1.4 KB
|
Rev | Line | |
---|
[261] | 1 | 'Classes/ActiveBasic/Windows/CriticalSection.ab
|
---|
| 2 |
|
---|
| 3 | Namespace ActiveBasic
|
---|
| 4 | Namespace Windows
|
---|
| 5 |
|
---|
[269] | 6 | Namespace Detail
|
---|
[303] | 7 | Const InterlockedExchangeAnyPointer(p, x) = InterlockedExchangePointer(ByVal VarPtr(p) As *VoidPtr, x)
|
---|
[269] | 8 | End Namespace
|
---|
| 9 |
|
---|
[261] | 10 | Class CriticalSection
|
---|
[411] | 11 | Implements System.IDisposable
|
---|
[261] | 12 | Public
|
---|
| 13 | Sub CriticalSection()
|
---|
| 14 | disposed = 0
|
---|
| 15 | InitializeCriticalSection(cs)
|
---|
| 16 | End Sub
|
---|
| 17 |
|
---|
| 18 | Sub ~CriticalSection()
|
---|
| 19 | Dispose()
|
---|
| 20 | End Sub
|
---|
| 21 |
|
---|
[411] | 22 | Sub Dispose()
|
---|
[261] | 23 | If InterlockedIncrement(disposed) = 0 Then
|
---|
| 24 | DeleteCriticalSection(cs)
|
---|
| 25 | End If
|
---|
| 26 | End Sub
|
---|
| 27 |
|
---|
[269] | 28 | Function Enter() As ActiveBasic.Windows.CriticalSectionLock
|
---|
[261] | 29 | Return New CriticalSectionLock(cs)
|
---|
| 30 | End Function
|
---|
| 31 | Private
|
---|
| 32 | cs As CRITICAL_SECTION
|
---|
| 33 | disposed As Long
|
---|
| 34 | End Class
|
---|
| 35 |
|
---|
| 36 | Class CriticalSectionLock
|
---|
[269] | 37 | ' Inherits System.IDisposable
|
---|
[261] | 38 | Public
|
---|
| 39 | Sub CriticalSectionLock(ByRef cs As CRITICAL_SECTION)
|
---|
| 40 | pcs = VarPtr(cs)
|
---|
| 41 | EnterCriticalSection(cs)
|
---|
| 42 | End Sub
|
---|
| 43 |
|
---|
| 44 | Sub ~CriticalSectionLock()
|
---|
| 45 | Dispose()
|
---|
| 46 | End Sub
|
---|
| 47 |
|
---|
| 48 | Sub Leave()
|
---|
| 49 | Dispose()
|
---|
| 50 | End Sub
|
---|
| 51 |
|
---|
[269] | 52 | /*Override*/ Sub Dispose()
|
---|
[335] | 53 | ' Dim pcsOld = ActiveBasic.Windows.Detail.InterlockedExchangeAnyPointer(pcs, 0)
|
---|
[439] | 54 | Dim pcsOld = InterlockedExchangePointer(ByVal VarPtr(pcs) As *VoidPtr, 0) As *CRITICAL_SECTION
|
---|
[335] | 55 | If pcsOld <> 0 Then
|
---|
| 56 | LeaveCriticalSection(ByVal pcsOld)
|
---|
[261] | 57 | End If
|
---|
| 58 | End Sub
|
---|
| 59 | Private
|
---|
| 60 | pcs As *CRITICAL_SECTION
|
---|
| 61 | End Class
|
---|
| 62 |
|
---|
| 63 | End Namespace 'Windows
|
---|
| 64 | End Namespace 'ActiveBasic
|
---|
Note:
See
TracBrowser
for help on using the repository browser.