Example #1
0
        /// <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>
        /// 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);
        }
Example #3
0
        /// <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();
        }
Example #4
0
 /// <summary>
 /// Increments the shared counter.
 /// </summary>
 public void Increment()
 {
     Runtime.SendEvent(CounterMachine, SharedCounterEvent.IncrementEvent());
 }
Example #5
0
 /// <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>
 /// Initializes the shared register.
 /// </summary>
 /// <param name="value">Initial value</param>
 /// <param name="Runtime">Runtime</param>
 public MockSharedRegister(T value, BugFindingRuntime Runtime)
 {
     this.Runtime    = Runtime;
     registerMachine = Runtime.CreateMachine(typeof(SharedRegisterMachine <T>));
     Runtime.SendEvent(registerMachine, SharedRegisterEvent.SetEvent(value));
 }