diff --git a/PowerThreadPool/Constants/CanCreateNewWorker.cs b/PowerThreadPool/Constants/CanCreateNewWorker.cs new file mode 100644 index 0000000..9e9918c --- /dev/null +++ b/PowerThreadPool/Constants/CanCreateNewWorker.cs @@ -0,0 +1,8 @@ +namespace PowerThreadPool.Constants +{ + internal enum CanCreateNewWorker + { + Allowed = 0, + NotAllowed = 1, + } +} diff --git a/PowerThreadPool/Constants/WorkerGettedFlags.cs b/PowerThreadPool/Constants/CanGetWork.cs similarity index 58% rename from PowerThreadPool/Constants/WorkerGettedFlags.cs rename to PowerThreadPool/Constants/CanGetWork.cs index d03e0c8..6958419 100644 --- a/PowerThreadPool/Constants/WorkerGettedFlags.cs +++ b/PowerThreadPool/Constants/CanGetWork.cs @@ -1,9 +1,9 @@ namespace PowerThreadPool.Constants { - internal enum WorkerGettedFlags + internal enum CanGetWork { - Free = 0, - Getted = 1, + Allowed = 0, + NotAllowed = 1, ToBeDisabled = 2, Disabled = -1, } diff --git a/PowerThreadPool/Constants/PoolRunningFlags.cs b/PowerThreadPool/Constants/PoolStates.cs similarity index 78% rename from PowerThreadPool/Constants/PoolRunningFlags.cs rename to PowerThreadPool/Constants/PoolStates.cs index ae7faf9..ef8a84d 100644 --- a/PowerThreadPool/Constants/PoolRunningFlags.cs +++ b/PowerThreadPool/Constants/PoolStates.cs @@ -1,6 +1,6 @@ namespace PowerThreadPool.Constants { - internal enum PoolRunningFlags + internal enum PoolStates { NotRunning = 0, IdleChecked = 1, diff --git a/PowerThreadPool/Constants/WorkHeldFlags.cs b/PowerThreadPool/Constants/WorkHeldStates.cs similarity index 73% rename from PowerThreadPool/Constants/WorkHeldFlags.cs rename to PowerThreadPool/Constants/WorkHeldStates.cs index 87fb8d8..83848e3 100644 --- a/PowerThreadPool/Constants/WorkHeldFlags.cs +++ b/PowerThreadPool/Constants/WorkHeldStates.cs @@ -1,6 +1,6 @@ namespace PowerThreadPool.Constants { - internal enum WorkHeldFlags + internal enum WorkHeldStates { NotHeld = 0, Held = 1 diff --git a/PowerThreadPool/Constants/WorkStealability.cs b/PowerThreadPool/Constants/WorkStealability.cs new file mode 100644 index 0000000..1640f4c --- /dev/null +++ b/PowerThreadPool/Constants/WorkStealability.cs @@ -0,0 +1,8 @@ +namespace PowerThreadPool.Constants +{ + internal enum WorkStealability + { + Allowed = 0, + NotAllowed = 1, + } +} diff --git a/PowerThreadPool/Constants/WorkerCreationFlags.cs b/PowerThreadPool/Constants/WorkerCreationFlags.cs deleted file mode 100644 index f7e1eba..0000000 --- a/PowerThreadPool/Constants/WorkerCreationFlags.cs +++ /dev/null @@ -1,8 +0,0 @@ -namespace PowerThreadPool.Constants -{ - internal enum WorkerCreationFlags - { - Allow = 0, - Reject = 1, - } -} diff --git a/PowerThreadPool/Constants/WorkerStealingFlags.cs b/PowerThreadPool/Constants/WorkerStealingFlags.cs deleted file mode 100644 index e019240..0000000 --- a/PowerThreadPool/Constants/WorkerStealingFlags.cs +++ /dev/null @@ -1,8 +0,0 @@ -namespace PowerThreadPool.Constants -{ - internal enum WorkerStealingFlags - { - Allow = 0, - Reject = 1, - } -} diff --git a/PowerThreadPool/Core/PowerThreadPool.Control.cs b/PowerThreadPool/Core/PowerThreadPool.Control.cs index d96f3f7..99b1149 100644 --- a/PowerThreadPool/Core/PowerThreadPool.Control.cs +++ b/PowerThreadPool/Core/PowerThreadPool.Control.cs @@ -108,7 +108,7 @@ private bool CheckIfRequestedStopAndGetWork(ref WorkBase work) /// public void Wait() { - if (_poolRunning == PoolRunningFlags.NotRunning) + if (_poolState == PoolStates.NotRunning) { return; } @@ -444,7 +444,7 @@ public Task>> FetchAsync(IEnumerable idList, /// Return false if no thread running public bool Stop(bool forceStop = false) { - if (_poolRunning == PoolRunningFlags.NotRunning) + if (_poolState == PoolStates.NotRunning) { return false; } diff --git a/PowerThreadPool/Core/PowerThreadPool.cs b/PowerThreadPool/Core/PowerThreadPool.cs index 84e0485..6808eba 100644 --- a/PowerThreadPool/Core/PowerThreadPool.cs +++ b/PowerThreadPool/Core/PowerThreadPool.cs @@ -45,7 +45,7 @@ public partial class PowerPool : IDisposable private bool _suspended; - private InterlockedFlag _createWorkerFlag = WorkerCreationFlags.Allow; + private InterlockedFlag _canCreateNewWorker = CanCreateNewWorker.Allowed; private PowerPoolOption _powerPoolOption; public PowerPoolOption PowerPoolOption @@ -61,9 +61,9 @@ public PowerPoolOption PowerPoolOption private System.Timers.Timer _poolTimer; - private InterlockedFlag _poolRunning = PoolRunningFlags.NotRunning; + private InterlockedFlag _poolState = PoolStates.NotRunning; - public bool PoolRunning => _poolRunning == PoolRunningFlags.Running; + public bool PoolRunning => _poolState == PoolStates.Running; private bool _poolStopping = false; public bool PoolStopping { get => _poolStopping; } @@ -287,7 +287,7 @@ private Worker GetWorker(bool longRunning) { if (_idleWorkerDic.TryRemove(firstWorkerID, out worker)) { - SpinWait.SpinUntil(() => worker.GettedFlag.TrySet(WorkerGettedFlags.Getted, WorkerGettedFlags.Free)); + SpinWait.SpinUntil(() => worker.CanGetWork.TrySet(CanGetWork.NotAllowed, CanGetWork.Allowed)); Interlocked.Decrement(ref _idleWorkerCount); if (longRunning) { @@ -299,13 +299,13 @@ private Worker GetWorker(bool longRunning) if (AliveWorkerCount < PowerPoolOption.MaxThreads + LongRunningWorkerCount) { - if (_createWorkerFlag.TrySet(WorkerCreationFlags.Reject, WorkerCreationFlags.Allow)) + if (_canCreateNewWorker.TrySet(CanCreateNewWorker.NotAllowed, CanCreateNewWorker.Allowed)) { if (AliveWorkerCount < PowerPoolOption.MaxThreads + LongRunningWorkerCount) { worker = new Worker(this); - worker.GettedFlag.InterlockedValue = WorkerGettedFlags.Getted; + worker.CanGetWork.InterlockedValue = CanGetWork.NotAllowed; if (_aliveWorkerDic.TryAdd(worker.ID, worker)) { @@ -318,7 +318,7 @@ private Worker GetWorker(bool longRunning) } } - _createWorkerFlag.InterlockedValue = WorkerCreationFlags.Allow; + _canCreateNewWorker.InterlockedValue = CanCreateNewWorker.Allowed; } } @@ -336,11 +336,11 @@ private Worker GetWorker(bool longRunning) int waitingWorkCountTemp = aliveWorker.WaitingWorkCount; if (waitingWorkCountTemp < min) { - if (aliveWorker.GettedFlag.TrySet(WorkerGettedFlags.Getted, WorkerGettedFlags.Free)) + if (aliveWorker.CanGetWork.TrySet(CanGetWork.NotAllowed, CanGetWork.Allowed)) { if (worker != null) { - worker.GettedFlag.TrySet(WorkerGettedFlags.Free, WorkerGettedFlags.Getted); + worker.CanGetWork.TrySet(CanGetWork.Allowed, CanGetWork.NotAllowed); } worker = aliveWorker; @@ -363,7 +363,7 @@ private Worker GetWorker(bool longRunning) /// private void CheckPoolStart() { - if (RunningWorkerCount == 0 && _poolRunning.TrySet(PoolRunningFlags.Running, PoolRunningFlags.NotRunning)) + if (RunningWorkerCount == 0 && _poolState.TrySet(PoolStates.Running, PoolStates.NotRunning)) { if (PoolStarted != null) { @@ -422,7 +422,7 @@ internal void CheckPoolIdle() if (RunningWorkerCount == 0 && WaitingWorkCount == 0 && - _poolRunning.TrySet(PoolRunningFlags.IdleChecked, PoolRunningFlags.Running) + _poolState.TrySet(PoolStates.IdleChecked, PoolStates.Running) ) { if (PoolIdled != null) @@ -459,7 +459,7 @@ private void IdleSetting() _cancellationTokenSource.Dispose(); _cancellationTokenSource = new CancellationTokenSource(); - _poolRunning.InterlockedValue = PoolRunningFlags.NotRunning; + _poolState.InterlockedValue = PoolStates.NotRunning; if (_poolStopping) { _poolStopping = false; diff --git a/PowerThreadPool/Core/Worker.cs b/PowerThreadPool/Core/Worker.cs index aac408e..748f9c7 100644 --- a/PowerThreadPool/Core/Worker.cs +++ b/PowerThreadPool/Core/Worker.cs @@ -24,9 +24,9 @@ internal class Worker : IDisposable internal int ID { get; set; } internal InterlockedFlag WorkerState { get; set; } = WorkerStates.Idle; - internal InterlockedFlag GettedFlag { get; set; } = WorkerGettedFlags.Free; - internal InterlockedFlag WorkHeld { get; set; } = WorkHeldFlags.NotHeld; - internal InterlockedFlag StealingFlag { get; set; } = WorkerStealingFlags.Allow; + internal InterlockedFlag CanGetWork { get; set; } = Constants.CanGetWork.Allowed; + internal InterlockedFlag WorkHeldState { get; set; } = WorkHeldStates.NotHeld; + internal InterlockedFlag WorkStealability { get; set; } = Constants.WorkStealability.Allowed; private IStealablePriorityCollection _waitingWorkIDPriorityCollection; private ConcurrentDictionary _waitingWorkDic = new ConcurrentDictionary(); @@ -143,7 +143,7 @@ private void ExecuteWork(PowerPool powerPool) private void ThreadInterrupted(PowerPool powerPool, ThreadInterruptedException ex) { - GettedFlag.InterlockedValue = WorkerGettedFlags.Disabled; + CanGetWork.InterlockedValue = Constants.CanGetWork.Disabled; WorkerStates origWorkState = WorkerState.InterlockedValue; WorkerState.InterlockedValue = WorkerStates.ToBeDisposed; @@ -240,7 +240,7 @@ private ExecuteResultBase ExecuteMain() executeResult = Work.SetExecuteResult(_powerPool, null, ex, Status.Failed); _powerPool.OnWorkErrorOccurred(ex, ErrorFrom.WorkLogic, executeResult); } - SpinWait.SpinUntil(() => WorkHeld == WorkHeldFlags.NotHeld); + SpinWait.SpinUntil(() => WorkHeldState == WorkHeldStates.NotHeld); Work.Worker = null; executeResult.ID = Work.ID; @@ -298,7 +298,7 @@ internal void SetWork(WorkBase work, bool resetted) if (!resetted) { - GettedFlag.InterlockedValue = WorkerGettedFlags.Free; + CanGetWork.InterlockedValue = Constants.CanGetWork.Allowed; } if (originalWorkerState == WorkerStates.Idle) @@ -398,13 +398,13 @@ private void StealWorksFromOtherWorker(ref string waitingWorkID, ref WorkBase wo int waitingWorkCountTemp = runningWorker.WaitingWorkCount; if (waitingWorkCountTemp >= 2 && waitingWorkCountTemp > max) { - if (!runningWorker.StealingFlag.TrySet(WorkerStealingFlags.Reject, WorkerStealingFlags.Allow)) + if (!runningWorker.WorkStealability.TrySet(Constants.WorkStealability.NotAllowed, Constants.WorkStealability.Allowed)) { continue; } if (worker != null) { - worker.StealingFlag.InterlockedValue = WorkerStealingFlags.Allow; + worker.WorkStealability.InterlockedValue = Constants.WorkStealability.Allowed; } max = waitingWorkCountTemp; worker = runningWorker; @@ -418,7 +418,7 @@ private void StealWorksFromOtherWorker(ref string waitingWorkID, ref WorkBase wo { stolenWorkList = worker.Steal(count); } - worker.StealingFlag.InterlockedValue = WorkerStealingFlags.Allow; + worker.WorkStealability.InterlockedValue = Constants.WorkStealability.Allowed; if (stolenWorkList != null) { foreach (WorkBase stolenWork in stolenWorkList) @@ -440,7 +440,7 @@ private void StealWorksFromOtherWorker(ref string waitingWorkID, ref WorkBase wo private bool TurnToIdle(ref string waitingWorkID, ref WorkBase work) { - SpinWait.SpinUntil(() => GettedFlag.TrySet(WorkerGettedFlags.ToBeDisabled, WorkerGettedFlags.Free)); + SpinWait.SpinUntil(() => CanGetWork.TrySet(Constants.CanGetWork.ToBeDisabled, Constants.CanGetWork.Allowed)); waitingWorkID = _waitingWorkIDPriorityCollection.Get(); if (waitingWorkID != null) @@ -450,7 +450,7 @@ private bool TurnToIdle(ref string waitingWorkID, ref WorkBase work) Interlocked.Decrement(ref _waitingWorkCount); } - GettedFlag.TrySet(WorkerGettedFlags.Free, WorkerGettedFlags.ToBeDisabled); + CanGetWork.TrySet(Constants.CanGetWork.Allowed, Constants.CanGetWork.ToBeDisabled); return false; } @@ -469,7 +469,7 @@ private bool TurnToIdle(ref string waitingWorkID, ref WorkBase work) WorkerState.InterlockedValue = WorkerStates.Idle; - GettedFlag.TrySet(WorkerGettedFlags.Free, WorkerGettedFlags.ToBeDisabled); + CanGetWork.TrySet(Constants.CanGetWork.Allowed, Constants.CanGetWork.ToBeDisabled); if (_powerPool._idleWorkerDic.TryAdd(ID, this)) { @@ -518,15 +518,15 @@ private void OnKillTimerElapsed(object s, ElapsedEventArgs e) if (_powerPool.IdleWorkerCount > _powerPool.PowerPoolOption.DestroyThreadOption.MinThreads) { // ① There is a possibility that a worker may still obtain and execute work between the - // time the _killTimer triggers OnKillTimerElapsed and when GettedFlag is set to Disabled. + // time the _killTimer triggers OnKillTimerElapsed and when CanGetWork is set to Disabled. SpinWait.SpinUntil(() => { - GettedFlag.TrySet(WorkerGettedFlags.Disabled, WorkerGettedFlags.Free, out WorkerGettedFlags origValue); + CanGetWork.TrySet(Constants.CanGetWork.Disabled, Constants.CanGetWork.Allowed, out CanGetWork origValue); // If situation ① occurs and _killTimer.Stop() has not yet been executed, the current state - // of GettedFlag will be Disabled, although this is an extremely rare case. - // Therefore, SpinUntil will exit either when GettedFlag is successfully set from Free to Disabled, - // or if the current state of GettedFlag is already Disabled. - return origValue == WorkerGettedFlags.Free || origValue == WorkerGettedFlags.Disabled; + // of CanGetWork will be Disabled, although this is an extremely rare case. + // Therefore, SpinUntil will exit either when CanGetWork is successfully set from Allowed to Disabled, + // or if the current state of CanGetWork is already Disabled. + return origValue == Constants.CanGetWork.Allowed || origValue == Constants.CanGetWork.Disabled; }); if (WorkerState.TrySet(WorkerStates.ToBeDisposed, WorkerStates.Idle)) @@ -543,10 +543,10 @@ private void OnKillTimerElapsed(object s, ElapsedEventArgs e) // Reaching this point means that WorkerState was not set from Idle to ToBeDisposed, // indicating that situation ① has occurred and that work is currently running. - // Therefore, reset the GettedFlag. This is also an extremely rare case, + // Therefore, reset the CanGetWork. This is also an extremely rare case, // and it's almost impossible to reproduce this situation with code coverage testing, // so code coverage testing for this line is ignored. - GettedFlag.TrySet(WorkerGettedFlags.Free, WorkerGettedFlags.Disabled); + CanGetWork.TrySet(Constants.CanGetWork.Allowed, Constants.CanGetWork.Disabled); } } diff --git a/PowerThreadPool/Helpers/WorkGuard.cs b/PowerThreadPool/Helpers/WorkGuard.cs index f6862d8..888ce45 100644 --- a/PowerThreadPool/Helpers/WorkGuard.cs +++ b/PowerThreadPool/Helpers/WorkGuard.cs @@ -32,12 +32,12 @@ private void Freeze() SpinWait.SpinUntil(() => (_worker = _work.Worker) != null); // Prevent the target work from being stolen by other workers using the work-stealing algorithm when it is stopped or canceled - SpinWait.SpinUntil(() => _worker.StealingFlag.TrySet(WorkerStealingFlags.Reject, WorkerStealingFlags.Allow)); + SpinWait.SpinUntil(() => _worker.WorkStealability.TrySet(WorkStealability.NotAllowed, WorkStealability.Allowed)); // Temporarily prevent the executing work from allowing the worker to switch to the next work when the current work is completed if (_isHoldWork) { - SpinWait.SpinUntil(() => _worker.WorkHeld.TrySet(WorkHeldFlags.Held, WorkHeldFlags.NotHeld)); + SpinWait.SpinUntil(() => _worker.WorkHeldState.TrySet(WorkHeldStates.Held, WorkHeldStates.NotHeld)); } } while (_work.Worker?.ID != _worker.ID); @@ -49,11 +49,11 @@ private void UnFreeze() { if (_worker != null) { - _worker.StealingFlag.InterlockedValue = WorkerStealingFlags.Allow; + _worker.WorkStealability.InterlockedValue = WorkStealability.Allowed; if (_isHoldWork) { - _worker.WorkHeld.InterlockedValue = WorkHeldFlags.NotHeld; + _worker.WorkHeldState.InterlockedValue = WorkHeldStates.NotHeld; } } } diff --git a/UnitTest/InterlockedFlagTest.cs b/UnitTest/InterlockedFlagTest.cs index 40e503f..6c6af77 100644 --- a/UnitTest/InterlockedFlagTest.cs +++ b/UnitTest/InterlockedFlagTest.cs @@ -5,13 +5,13 @@ namespace UnitTest { public class InterlockedFlagTest { - InterlockedFlag _gettedLock0 = WorkerGettedFlags.Free; - InterlockedFlag _gettedLock1 = WorkerGettedFlags.Free; + InterlockedFlag _canGetWork0 = CanGetWork.Allowed; + InterlockedFlag _canGetWork1 = CanGetWork.Allowed; private void InitFlags() { - _gettedLock0 = WorkerGettedFlags.Free; - _gettedLock1 = WorkerGettedFlags.Free; + _canGetWork0 = CanGetWork.Allowed; + _canGetWork1 = CanGetWork.Allowed; } [Fact] @@ -19,8 +19,8 @@ public void TestGetSet() { InitFlags(); - _gettedLock0.InterlockedValue = WorkerGettedFlags.Disabled; - Assert.Equal(WorkerGettedFlags.Disabled, _gettedLock0.InterlockedValue); + _canGetWork0.InterlockedValue = CanGetWork.Disabled; + Assert.Equal(CanGetWork.Disabled, _canGetWork0.InterlockedValue); } [Fact] @@ -28,8 +28,8 @@ public void TestValue() { InitFlags(); - _gettedLock0.InterlockedValue = WorkerGettedFlags.Disabled; - Assert.Equal(WorkerGettedFlags.Disabled, _gettedLock0.Value); + _canGetWork0.InterlockedValue = CanGetWork.Disabled; + Assert.Equal(CanGetWork.Disabled, _canGetWork0.Value); } [Fact] @@ -37,8 +37,8 @@ public void TestDebuggerDisplay() { InitFlags(); - string dd = _gettedLock0.DebuggerDisplay; - Assert.Equal("WorkerGettedFlags.Free", dd); + string dd = _canGetWork0.DebuggerDisplay; + Assert.Equal("CanGetWork.Allowed", dd); } [Fact] @@ -46,8 +46,8 @@ public void TestGet() { InitFlags(); - _gettedLock0.InterlockedValue = WorkerGettedFlags.Disabled; - Assert.Equal(WorkerGettedFlags.Disabled, _gettedLock0.Get()); + _canGetWork0.InterlockedValue = CanGetWork.Disabled; + Assert.Equal(CanGetWork.Disabled, _canGetWork0.Get()); } [Fact] @@ -56,12 +56,12 @@ public void TestTrySet() InitFlags(); bool res; - res = _gettedLock0.TrySet(WorkerGettedFlags.Disabled, WorkerGettedFlags.Free); - Assert.Equal(WorkerGettedFlags.Disabled, _gettedLock0.Get()); + res = _canGetWork0.TrySet(CanGetWork.Disabled, CanGetWork.Allowed); + Assert.Equal(CanGetWork.Disabled, _canGetWork0.Get()); Assert.True(res); - res = _gettedLock0.TrySet(WorkerGettedFlags.Disabled, WorkerGettedFlags.Free); - Assert.Equal(WorkerGettedFlags.Disabled, _gettedLock0.Get()); + res = _canGetWork0.TrySet(CanGetWork.Disabled, CanGetWork.Allowed); + Assert.Equal(CanGetWork.Disabled, _canGetWork0.Get()); Assert.False(res); } @@ -70,15 +70,15 @@ public void TestTrySetWithOrigValueParam() { InitFlags(); - WorkerGettedFlags orig; + CanGetWork orig; bool res; - res = _gettedLock0.TrySet(WorkerGettedFlags.Disabled, WorkerGettedFlags.Free, out orig); - Assert.Equal(WorkerGettedFlags.Disabled, _gettedLock0.Get()); - Assert.Equal(WorkerGettedFlags.Free, orig); + res = _canGetWork0.TrySet(CanGetWork.Disabled, CanGetWork.Allowed, out orig); + Assert.Equal(CanGetWork.Disabled, _canGetWork0.Get()); + Assert.Equal(CanGetWork.Allowed, orig); Assert.True(res); - res = _gettedLock0.TrySet(WorkerGettedFlags.Disabled, WorkerGettedFlags.Free, out orig); - Assert.Equal(WorkerGettedFlags.Disabled, orig); + res = _canGetWork0.TrySet(CanGetWork.Disabled, CanGetWork.Allowed, out orig); + Assert.Equal(CanGetWork.Disabled, orig); Assert.False(res); } @@ -88,23 +88,23 @@ public void TestOperator1() InitFlags(); bool res; - res = _gettedLock0 == _gettedLock1; + res = _canGetWork0 == _canGetWork1; Assert.True(res); - res = _gettedLock0 != _gettedLock1; + res = _canGetWork0 != _canGetWork1; Assert.False(res); - _gettedLock0 = WorkerGettedFlags.ToBeDisabled; - res = _gettedLock0 == _gettedLock1; + _canGetWork0 = CanGetWork.ToBeDisabled; + res = _canGetWork0 == _canGetWork1; Assert.False(res); - res = _gettedLock0 == _gettedLock1; + res = _canGetWork0 == _canGetWork1; Assert.False(res); - _gettedLock0 = null; - res = _gettedLock0 == _gettedLock1; + _canGetWork0 = null; + res = _canGetWork0 == _canGetWork1; Assert.False(res); - _gettedLock1 = null; - res = _gettedLock0 == _gettedLock1; + _canGetWork1 = null; + res = _canGetWork0 == _canGetWork1; Assert.True(res); - _gettedLock0 = WorkerGettedFlags.ToBeDisabled; - res = _gettedLock0 == _gettedLock1; + _canGetWork0 = CanGetWork.ToBeDisabled; + res = _canGetWork0 == _canGetWork1; Assert.False(res); } @@ -114,17 +114,17 @@ public void TestOperator2() InitFlags(); bool res; - res = _gettedLock0 == WorkerGettedFlags.Free; + res = _canGetWork0 == CanGetWork.Allowed; Assert.True(res); - res = _gettedLock0 != WorkerGettedFlags.Free; + res = _canGetWork0 != CanGetWork.Allowed; Assert.False(res); - _gettedLock0 = WorkerGettedFlags.ToBeDisabled; - res = _gettedLock0 == WorkerGettedFlags.Free; + _canGetWork0 = CanGetWork.ToBeDisabled; + res = _canGetWork0 == CanGetWork.Allowed; Assert.False(res); - res = _gettedLock0 == WorkerGettedFlags.Free; + res = _canGetWork0 == CanGetWork.Allowed; Assert.False(res); - _gettedLock0 = null; - res = _gettedLock0 == WorkerGettedFlags.Free; + _canGetWork0 = null; + res = _canGetWork0 == CanGetWork.Allowed; Assert.False(res); } @@ -133,10 +133,10 @@ public void Testimplicit() { InitFlags(); - _gettedLock0 = WorkerGettedFlags.ToBeDisabled; - WorkerGettedFlags f = _gettedLock0; - Assert.Equal(WorkerGettedFlags.ToBeDisabled, _gettedLock0.Value); - Assert.Equal(WorkerGettedFlags.ToBeDisabled, f); + _canGetWork0 = CanGetWork.ToBeDisabled; + CanGetWork f = _canGetWork0; + Assert.Equal(CanGetWork.ToBeDisabled, _canGetWork0.Value); + Assert.Equal(CanGetWork.ToBeDisabled, f); } [Fact] @@ -145,12 +145,12 @@ public void TestEquals1() InitFlags(); bool res; - res = _gettedLock0.Equals(_gettedLock1); + res = _canGetWork0.Equals(_canGetWork1); Assert.True(res); - _gettedLock0 = WorkerGettedFlags.ToBeDisabled; - res = _gettedLock0.Equals(_gettedLock1); + _canGetWork0 = CanGetWork.ToBeDisabled; + res = _canGetWork0.Equals(_canGetWork1); Assert.False(res); - res = _gettedLock0.Equals(_gettedLock1); + res = _canGetWork0.Equals(_canGetWork1); Assert.False(res); } @@ -160,12 +160,12 @@ public void TestEquals2() InitFlags(); bool res; - res = _gettedLock0.Equals(WorkerGettedFlags.Free); + res = _canGetWork0.Equals(CanGetWork.Allowed); Assert.True(res); - _gettedLock0 = WorkerGettedFlags.ToBeDisabled; - res = _gettedLock0.Equals(WorkerGettedFlags.Free); + _canGetWork0 = CanGetWork.ToBeDisabled; + res = _canGetWork0.Equals(CanGetWork.Allowed); Assert.False(res); - res = _gettedLock0.Equals(WorkerGettedFlags.Free); + res = _canGetWork0.Equals(CanGetWork.Allowed); Assert.False(res); } @@ -175,9 +175,9 @@ public void TestEquals3() InitFlags(); bool res; - res = _gettedLock0.Equals(null); + res = _canGetWork0.Equals(null); Assert.False(res); - res = _gettedLock0.Equals(new PowerThreadPool.PowerPool()); + res = _canGetWork0.Equals(new PowerThreadPool.PowerPool()); Assert.False(res); } @@ -186,11 +186,11 @@ public void TestGetHashCode() { InitFlags(); - int hash0 = _gettedLock0.GetHashCode(); - int hash1 = _gettedLock0.GetHashCode(); - int hash2 = _gettedLock1.GetHashCode(); - _gettedLock1 = WorkerGettedFlags.ToBeDisabled; - int hash3 = _gettedLock1.GetHashCode(); + int hash0 = _canGetWork0.GetHashCode(); + int hash1 = _canGetWork0.GetHashCode(); + int hash2 = _canGetWork1.GetHashCode(); + _canGetWork1 = CanGetWork.ToBeDisabled; + int hash3 = _canGetWork1.GetHashCode(); Assert.Equal(hash0, hash1); Assert.Equal(hash1, hash2); Assert.NotEqual(hash2, hash3);