/// <summary> /// Gets the current value of the shared counter. /// </summary> /// <returns>Current value</returns> public int GetValue() { var currentMachine = Runtime.GetCurrentMachine(); Runtime.SendEvent(CounterMachine, SharedCounterEvent.GetEvent(currentMachine.Id)); var response = currentMachine.Receive(typeof(SharedCounterResponseEvent)).Result; return((response as SharedCounterResponseEvent).Value); }
/// <summary> /// Sets the counter to a value atomically if it is equal to a given value. /// </summary> /// <param name="value">Value to set</param> /// <param name="comparand">Value to compare against</param> /// <returns>The original value of the counter</returns> public int CompareExchange(int value, int comparand) { var currentMachine = Runtime.GetCurrentMachine(); Runtime.SendEvent(CounterMachine, SharedCounterEvent.CasEvent(currentMachine.Id, value, comparand)); var response = currentMachine.Receive(typeof(SharedCounterResponseEvent)).Result; return((response as SharedCounterResponseEvent).Value); }
/// <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 = this.Runtime.GetCurrentMachine(); this.Runtime.SendEvent(this.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> /// Adds a value to the counter atomically. /// </summary> public int Add(int value) { var currentMachine = this.Runtime.GetExecutingMachine <Machine>(); this.Runtime.SendEvent(this.CounterMachine, SharedCounterEvent.AddEvent(currentMachine.Id, value)); var response = currentMachine.Receive(typeof(SharedCounterResponseEvent)).Result; return((response as SharedCounterResponseEvent).Value); }
/// <summary> /// Decrements the shared counter. /// </summary> public void Decrement() { Runtime.SendEvent(CounterMachine, SharedCounterEvent.DecrementEvent()); }
/// <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)); }
/// <summary> /// Increments the shared counter. /// </summary> public void Increment() { Runtime.SendEvent(this.CounterMachine, SharedCounterEvent.IncrementEvent()); }