|
|
|
@ -6,12 +6,30 @@ using System.Threading; |
|
|
|
namespace Sync_Ueb02_Latch |
|
|
|
namespace Sync_Ueb02_Latch |
|
|
|
{ |
|
|
|
{ |
|
|
|
class Latch : ISynch |
|
|
|
class Latch : ISynch |
|
|
|
{ private ManualResetEvent waitHandle = new(false); |
|
|
|
{ |
|
|
|
|
|
|
|
private ManualResetEvent waitHandle = new(false); |
|
|
|
|
|
|
|
private static uint countAquired = 0; |
|
|
|
|
|
|
|
private static object syncLock = new(); |
|
|
|
|
|
|
|
|
|
|
|
public void Acquire() |
|
|
|
public void Acquire() |
|
|
|
{ |
|
|
|
{ |
|
|
|
|
|
|
|
lock (syncLock) |
|
|
|
|
|
|
|
{ |
|
|
|
|
|
|
|
countAquired++; |
|
|
|
|
|
|
|
} |
|
|
|
this.waitHandle.WaitOne(); |
|
|
|
this.waitHandle.WaitOne(); |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
public uint GetAmountOfAquires() |
|
|
|
|
|
|
|
{ |
|
|
|
|
|
|
|
uint readCount = 0; |
|
|
|
|
|
|
|
lock(syncLock) |
|
|
|
|
|
|
|
{ |
|
|
|
|
|
|
|
readCount = countAquired; |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
return readCount; |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
public void Release() |
|
|
|
public void Release() |
|
|
|
{ |
|
|
|
{ |
|
|
|
this.waitHandle.Set(); |
|
|
|
this.waitHandle.Set(); |
|
|
|
|