/// <summary> /// Adds a new key to the dictionary, if it doesn’t already exist in the dictionary. /// </summary> /// <param name="key">Key</param> /// <param name="value">Value</param> /// <returns>True or false depending on whether the new key/value pair was added.</returns> public bool TryAdd(TKey key, TValue value) { var currentMachine = Runtime.GetCurrentMachine(); Runtime.SendEvent(DictionaryMachine, SharedDictionaryEvent.TryAddEvent(key, value, currentMachine.Id)); var e = currentMachine.Receive(typeof(SharedDictionaryResponseEvent <bool>)).Result as SharedDictionaryResponseEvent <bool>; return(e.Value); }
/// <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> /// Reads and updates the register. /// </summary> /// <param name="func">Update function</param> /// <returns>Resulting value of the register</returns> public T Update(Func <T, T> func) { var currentMachine = Runtime.GetCurrentMachine(); Runtime.SendEvent(registerMachine, SharedRegisterEvent.UpdateEvent(func, currentMachine.Id)); var e = currentMachine.Receive(typeof(SharedRegisterResponseEvent <T>)).Result as SharedRegisterResponseEvent <T>; return(e.Value); }
/// <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)); var currentMachine = Runtime.GetCurrentMachine(); Runtime.SendEvent(CounterMachine, SharedCounterEvent.SetEvent(currentMachine.Id, value)); currentMachine.Receive(typeof(SharedCounterResponseEvent)).Wait(); }