/// <summary> /// Sets the counter to a value atomically. /// </summary> /// <param name="value">Value to set</param> /// <returns>The original value of the counter</returns> public int Exchange(int value) { var currentMachine = Runtime.GetCurrentMachine(); Runtime.SendEvent(CounterMachine, SharedCounterEvent.SetEvent(currentMachine.Id, value)); var response = currentMachine.Receive(typeof(SharedCounterResponseEvent)).Result; return((response as SharedCounterResponseEvent).Value); }
/// <summary> /// Initializes the shared counter. /// </summary> /// <param name="value">Initial value</param> /// <param name="runtime">TestingRuntime</param> public MockSharedCounter(int value, TestingRuntime runtime) { this.Runtime = runtime; this.CounterMachine = this.Runtime.CreateMachine(typeof(SharedCounterMachine)); var currentMachine = this.Runtime.GetCurrentMachine(); this.Runtime.SendEvent(this.CounterMachine, SharedCounterEvent.SetEvent(currentMachine.Id, value)); currentMachine.Receive(typeof(SharedCounterResponseEvent)).Wait(); }
/// <summary> /// Initializes the shared counter. /// </summary> /// <param name="value">Initial value</param> /// <param name="Runtime">BugFindingRuntime</param> public MockSharedCounter(int value, BugFindingRuntime Runtime) { this.Runtime = Runtime; CounterMachine = Runtime.CreateMachine(typeof(SharedCounterMachine)); Runtime.SendEvent(CounterMachine, SharedCounterEvent.SetEvent(value)); }