[419] | 1 | ' Classes/System/Threading/Semaphore.ab
|
---|
| 2 |
|
---|
| 3 | #ifndef __SYSTEM_THREADING_SEMAPHORE_AB__
|
---|
| 4 | #define __SYSTEM_THREADING_SEMAPHORE_AB__
|
---|
| 5 |
|
---|
| 6 | Namespace System
|
---|
| 7 | Namespace Threading
|
---|
| 8 |
|
---|
| 9 | Class Semaphore
|
---|
| 10 | Inherits System.Threading.WaitHandle
|
---|
| 11 |
|
---|
| 12 | Public
|
---|
| 13 | Sub Semaphore(initialCount As Long, maximumCount As Long)
|
---|
| 14 | This.Handle(CreateSemaphore(NULL,initialCount,maximumCount,NULL))
|
---|
| 15 | End Sub
|
---|
| 16 | Sub Semaphore(initialCount As Long, maximumCount As Long, name As String)
|
---|
| 17 | This.Handle(CreateSemaphore(NULL,initialCount,maximumCount,ToTCStr(name)))
|
---|
| 18 | End Sub
|
---|
| 19 | Sub Semaphore(initialCount As Long, maximumCount As Long, name As String, ByRef createdNew As Boolean)
|
---|
| 20 | This.Handle(CreateSemaphore(NULL,initialCount,maximumCount,ToTCStr(name)))
|
---|
| 21 | If ERROR_ALREADY_EXISTS=GetLastError() Then createdNew=False Else createdNew=True
|
---|
| 22 | 'Throw ArgumentException
|
---|
| 23 | 'Throw ArgumentOutOfRangeException
|
---|
| 24 | 'Throw IOException
|
---|
| 25 | 'Throw UnauthorizedAccessException
|
---|
| 26 | 'Throw WaitHandleCannotBeOpenedException
|
---|
| 27 | End Sub
|
---|
| 28 | /* Sub Semaphore(initialCount As Long, maximumCount As Long, name As String, ByRef createdNew As Boolean, semaphoreSecurity As SemaphoreSecurity)
|
---|
| 29 | TODO
|
---|
| 30 | End Sub*/
|
---|
| 31 |
|
---|
| 32 | Static Function OpenExisting (name As String) As Semaphore
|
---|
| 33 | This.Handle(OpenSemaphore(SEMAPHORE_ALL_ACCESS,FALSE,ToTCStr(name)))
|
---|
| 34 | 'Throw ArgumentException
|
---|
| 35 | 'Throw ArgumentNullException
|
---|
| 36 | 'Throw WaitHandleCannotBeOpenedException
|
---|
| 37 | 'Throw IOException
|
---|
| 38 | 'Throw UnauthorizedAccessException
|
---|
| 39 | End Function
|
---|
| 40 |
|
---|
| 41 | /* Static Function OpenExisting (String, SemaphoreRights) As Semaphore
|
---|
| 42 | TODO
|
---|
| 43 | End Function*/
|
---|
| 44 |
|
---|
| 45 | Function Release() As Long
|
---|
| 46 | If ReleaseSemaphore(This.Handle(),1,Release) = 0 Then
|
---|
| 47 | 'SemaphoreFullException
|
---|
| 48 | 'IOException
|
---|
| 49 | 'UnauthorizedAccessException
|
---|
| 50 | End If
|
---|
| 51 | End Function
|
---|
| 52 | Function Release(releaseCount As Long) As Long
|
---|
| 53 | If ReleaseSemaphore(This.Handle(),releaseCount,Release) = 0 Then
|
---|
| 54 | 'ArgumentOutOfRangeException
|
---|
| 55 | 'SemaphoreFullException
|
---|
| 56 | 'IOException
|
---|
| 57 | 'UnauthorizedAccessException
|
---|
| 58 | End If
|
---|
| 59 | End Function
|
---|
| 60 |
|
---|
| 61 | End Class
|
---|
| 62 |
|
---|
| 63 | End Namespace 'Threading
|
---|
| 64 | End Namespace 'System
|
---|
| 65 |
|
---|
| 66 | #endif
|
---|