Esempio n. 1
0
        // thread cas data
        void thread_cas_data(object state)
        {
            var param = state as object[];

            Assert.IsNotNull(param);

            var cache = param[0] as Cache <int, string>;

            Assert.IsNotNull(cache);

            int index = (int)param[1];

            string data;
            int    cas;

            for (int i = 0; i < cache_data_count; i++)
            {
                bool ret = cache.Get(cache_data_count * index + i, out data, out cas);
                Assert.IsTrue(ret);
                Assert.AreEqual(data, check_data.Substring(0, data_size_set[cache_data_count * index + i]));

                ret = cache.Set(cache_data_count * index + i, check_data.Substring(0, data_size_set[cache_data_count * index + i]), ref cas);
                Atomic.Inc(ref setCount);
                Assert.IsTrue(ret);
            }
        }
Esempio n. 2
0
 public static void AtomicAdd(this VariableView <Vector4> target, Vector4 operand)
 {
     Atomic.Add(ref target.SubView <float>(Vector4XOffset).Value, operand.X);
     Atomic.Add(ref target.SubView <float>(Vector4YOffset).Value, operand.Y);
     Atomic.Add(ref target.SubView <float>(Vector4ZOffset).Value, operand.Z);
     Atomic.Add(ref target.SubView <float>(Vector4WOffset).Value, operand.W);
 }
Esempio n. 3
0
        public ThreadFiber()
        {
            _actions = Atomic.Create(ImmutableList<Action>.EmptyList);

            _thread = CreateThread();
            _thread.Start();
        }
Esempio n. 4
0
 public void Release()
 {
     if (Group.IsFirstThread)
     {
         Atomic.Add(ref address.Value, 1);
     }
 }
 protected ExprTableEvalStrategyUngroupedBase(
     ILockable @lock,
     Atomic <ObjectArrayBackedEventBean> aggregationState)
 {
     _lock            = @lock;
     AggregationState = aggregationState;
 }
Esempio n. 6
0
        private void HandleConfig()
        {
            if (!File.Exists("config.json"))
            {
                ConfigData newConfig = new ConfigData()
                {
                    Token = "YOUR_TOKEN_GOES_HERE"
                };

                ChannelConfig chConf = new ChannelConfig();

                newConfig.ChConfig   = chConf;
                newConfig.LastHeight = (int)this.ActualHeight;
                newConfig.LastWidth  = (int)this.ActualWidth;

                string json        = JsonConvert.SerializeObject(newConfig, Formatting.Indented);
                byte[] fileContent = Encoding.UTF8.GetBytes(json);

                Atomic.WriteFile("config.json", new MemoryStream(fileContent));

                config = JsonConvert.DeserializeObject <ConfigData>(File.ReadAllText("config.json"));
            }
            else
            {
                // this is also loaded on sync channel button, in case you ever change your token while program is still running i guess?
                // but please dont change token while program is still running wtf u doin
                config = JsonConvert.DeserializeObject <ConfigData>(File.ReadAllText("config.json"));

                this.Height = config.LastHeight;
                this.Width  = config.LastWidth;
            }
        }
        public void Atomic_Int_Store_Should_Fail()
        {
            var atomicInteger = new Atomic <int>(int.MaxValue);

            Assert.Throws <InvalidOperationException>(() => atomicInteger.Store(int.MinValue, MemoryOrder.Acquire));
            Assert.Throws <NotSupportedException>(() => atomicInteger.Store(int.MinValue, MemoryOrder.Consume));
        }
        public void Atomic_Long_Load_Should_Fail()
        {
            var atomicLong = new Atomic <long>(long.MaxValue);

            Assert.Throws <InvalidOperationException>(() => atomicLong.Load(MemoryOrder.Release));
            Assert.Throws <NotSupportedException>(() => atomicLong.Load(MemoryOrder.Consume));
        }
        public void Atomic_Int_Load_Should_Fail()
        {
            var atomicInteger = new Atomic <int>(int.MaxValue);

            Assert.Throws <InvalidOperationException>(() => atomicInteger.Load(MemoryOrder.Release));
            Assert.Throws <NotSupportedException>(() => atomicInteger.Load(MemoryOrder.Consume));
        }
        public void Atomic_Int_Store_Should_Success(int initialValue, int storeValue, MemoryOrder order)
        {
            var atomicInteger = new Atomic <int>(initialValue, MemoryOrder.Relaxed);

            atomicInteger.Store(storeValue, order);
            Assert.Equal(storeValue, atomicInteger.Value);
        }
        public void Atomic_Bool_Store_Should_Success(bool initialValue, bool storeValue, MemoryOrder order)
        {
            var atomicBoolean = new Atomic <bool>(initialValue, MemoryOrder.Relaxed);

            atomicBoolean.Store(storeValue, order);
            Assert.Equal(storeValue, atomicBoolean.Value);
        }
        public void Atomic_Bool_Store_Should_Fail()
        {
            var atomicBoolean = new Atomic <bool>(true);

            Assert.Throws <InvalidOperationException>(() => atomicBoolean.Store(false, MemoryOrder.Acquire));
            Assert.Throws <NotSupportedException>(() => atomicBoolean.Store(false, MemoryOrder.Consume));
        }
        public void Atomic_Bool_Load_Should_Fail()
        {
            var atomicBoolean = new Atomic <bool>(true);

            Assert.Throws <InvalidOperationException>(() => atomicBoolean.Load(MemoryOrder.Release));
            Assert.Throws <NotSupportedException>(() => atomicBoolean.Load(MemoryOrder.Consume));
        }
        public void Atomic_Long_Store_Should_Fail()
        {
            var atomicLong = new Atomic <long>(long.MaxValue);

            Assert.Throws <InvalidOperationException>(() => atomicLong.Store(long.MinValue, MemoryOrder.Acquire));
            Assert.Throws <NotSupportedException>(() => atomicLong.Store(long.MinValue, MemoryOrder.Consume));
        }
        public void Atomic_Long_Store_Should_Success(long initialValue, long storeValue, MemoryOrder order)
        {
            var atomicLong = new Atomic <long>(initialValue, MemoryOrder.Relaxed);

            atomicLong.Store(storeValue, order);
            Assert.Equal(storeValue, atomicLong.Value);
        }
Esempio n. 16
0
 public void Reset()
 {
     if (Group.IsFirstThread)
     {
         Atomic.Exchange(ref address.Value, 0);
     }
 }
Esempio n. 17
0
    void FixedUpdate()
    {
        foreach (Atomic atom in this.nearbyAtoms)
        {
            rb.AddForce(CoulombForce(atom));
        }

        if (isBrokenJoint == true)
        {
            Debug.Log("JOINT BREAK!");
            isBrokenJoint = false;

            Atomic otherAtom = FindDivorcedAtom();
            if (otherAtom == null)
            {
                return;
            }

            BreakBondWith(otherAtom);
        }

        // just checking
        this.totalElectrons          = TotalElectrons();
        this.netCharge               = NetCharge();
        this.bondedAtomsCount        = SharedElectrons();
        this.nearbyAtomsCount        = nearbyAtoms.Count;
        this.baseValenceElectrons    = BaseValenceElectrons();
        this.valenceElectrons        = ValenceElectrons();
        this.shareableElectrons      = ShareableElectrons();
        this.shareableHoles          = ShareableHoles();
        this.valenceOrbitalPositions = ValenceOrbitalPositions();
    }
Esempio n. 18
0
        public void CloseApp(object sender, RoutedEventArgs e)
        {
            /*
             * MessageBoxImage mbi = new MessageBoxImage();
             * string desc = "Are you sure you want to exit?\nAll the ongoing downloading will pause. (check for downloading, then warn?)";
             *
             * // should be custom messagebox... because.
             * MessageBoxResult result = MessageBox.Show(desc, "Close app", MessageBoxButton.YesNo, mbi, MessageBoxResult.Yes);
             *
             * if (result == MessageBoxResult.No)
             * {
             *  return;
             * }
             */

            config.LastWidth  = (int)this.ActualWidth;
            config.LastHeight = (int)this.ActualHeight;

            string json = JsonConvert.SerializeObject(config, Formatting.Indented);

            byte[] fileContent = Encoding.UTF8.GetBytes(json);

            Atomic.OverwriteFile("config.json", new MemoryStream(fileContent), "config.json.backup");

            Application.Current.Shutdown();
        }
Esempio n. 19
0
 private void PrepareForNewConfig()
 {
     _stack                 = new NaiveLockFreeStack();
     _popped                = new List <int>();
     _poppedInOrder         = new List <int>();
     _pushingThreadFinished = new Atomic <bool>();
 }
Esempio n. 20
0
 public TableInstanceUngroupedImpl(
     Table table,
     AgentInstanceContext agentInstanceContext)
     : base(table, agentInstanceContext)
 {
     eventReference = new Atomic<ObjectArrayBackedEventBean>(null);
 }
Esempio n. 21
0
        /// <inheritdoc />
        public ValueTask <bool> MoveNextAsync()
        {
            var state = Atomic.Lock(ref _state);

            switch (state)
            {
            case _sInitial:
                _state = _sInitial;
                throw new InvalidOperationException("GetAsyncEnumerator was not called.");

            case _sEmitting:
                _tsAccepting.Reset();
                _state = _sAccepting;
                _tsEmitting.SetResult(true);
                return(_tsAccepting.Task);

            case _sAccepting:
                _state = _sAccepting;
                throw new InvalidOperationException("MoveNextAsync is not reentrant.");

            case _sFinal:
                Current = default;
                _state  = _sFinal;
                return(new(_atmbFinal.Task));

            default:
                _state = state;
                throw new Exception(state + "???");
            }
        }
Esempio n. 22
0
File: Time.cs Progetto: tinudu/Linx
 private void TimerCallback(object _)
 {
     if (Atomic.CompareExchange(ref _state, _sInitial, _sWaiting) == _sWaiting)
     {
         _tsDelay.SetResult();
     }
 }
Esempio n. 23
0
File: Time.cs Progetto: tinudu/Linx
                private void SetFinal(Exception error)
                {
                    Debug.Assert(error is not null);

                    var state = Atomic.Lock(ref _state);

                    switch (state)
                    {
                    case _sInitial:
                        _tsDelay.Reset();
                        _state = _sFinal;
                        _ctr.Dispose();
                        _tsDelay.SetException(error);
                        break;

                    case _sWaiting:
                        _state = _sFinal;
                        _ctr.Dispose();
                        _tsDelay.SetException(error);
                        break;

                    case _sFinal:
                        _state = _sFinal;
                        break;

                    default:
                        _state = state;
                        throw new Exception(_state + "???");
                    }
                }
Esempio n. 24
0
        public void RemoveFolder(object sender, RoutedEventArgs e)
        {
            Button b = sender as Button;

            b.Opacity = 0.1;

            MessageBoxImage mbi  = new MessageBoxImage();
            string          desc = $"Do you wish to {_deleteButtonText.Text}";

            // should be custom messagebox... but meh
            MessageBoxResult result = MessageBox.Show(desc, "Remove from the list", MessageBoxButton.YesNo, mbi, MessageBoxResult.Yes);

            if (result == MessageBoxResult.Yes)
            {
                Tiles.Remove(b.CommandParameter.ToString());
                Counters.Remove(b.CommandParameter.ToString());
                chConfig.list.Remove(b.CommandParameter.ToString());
                config.ChConfig = chConfig;

                UpdateFolderGrid(true);
                RefreshDropboxList();
                myTray.UpdateTrayFolders();

                string json        = JsonConvert.SerializeObject(config, Formatting.Indented);
                byte[] fileContent = Encoding.UTF8.GetBytes(json);

                Atomic.OverwriteFile("config.json", new MemoryStream(fileContent), "config.json.backup");
            }
        }
Esempio n. 25
0
        public void Atomic_Implicit_AcqRel_Should_Success()
        {
            Atomic <Guid> atomicGuid = SessionValue;

            Assert.NotNull(atomicGuid);
            Assert.Equal(SessionValue, atomicGuid.Value);
        }
Esempio n. 26
0
 private void PrepareForNewConfig()
 {
     interestedF    = new Atomic <int>();
     interestedS    = new Atomic <int>();
     victim         = new Atomic <int>();
     _threadsPassed = 0;
 }
Esempio n. 27
0
        /// <summary>
        /// Computes the pixel variances and their average
        /// </summary>
        public override void OnEndIteration(int curIteration)
        {
            // Update the mean and moment based on the buffered image of the current iteration
            Parallel.For(0, momentImage.Height, row => {
                for (int col = 0; col < momentImage.Width; ++col)
                {
                    float val = bufferImage.GetPixel(col, row);
                    momentImage.AtomicAdd(col, row, val * val / curIteration);
                    meanImage.AtomicAdd(col, row, val / curIteration);
                }
            });

            // Blur both buffers to get a more stable estimate.
            // TODO this could be done in-place by directly splatting in multiple pixels above
            BoxFilter       filter        = new(1);
            MonochromeImage blurredMean   = new(meanImage.Width, meanImage.Height);
            MonochromeImage blurredMoment = new(meanImage.Width, meanImage.Height);

            filter.Apply(meanImage, blurredMean);
            filter.Apply(momentImage, blurredMoment);

            // Compute the final variance and update the main image
            Average = 0;
            Parallel.For(0, momentImage.Height, row => {
                for (int col = 0; col < momentImage.Width; ++col)
                {
                    float mean     = blurredMean.GetPixel(col, row);
                    float variance = blurredMoment.GetPixel(col, row) - mean * mean;
                    variance      /= (mean * mean + 0.001f);
                    Image.SetPixelChannel(col, row, 0, variance);
                    Atomic.AddFloat(ref Average, variance);
                }
            });
            Average /= momentImage.Height * momentImage.Width;
        }
Esempio n. 28
0
 private void PrepareForNewConfig()
 {
     A = new Atomic <int>();
     B = new Atomic <int>();
     _fastStoreDone = false;
     _serializeDone = false;
 }
Esempio n. 29
0
        private void SetFinal(Exception error)
        {
            var state = Atomic.Lock(ref _state);

            switch (state)
            {
            case _sInitial:
                _state = _sInitial;
                throw new InvalidOperationException();

            case _sEmitting:
                _state = _sFinal;
                _ctr.Dispose();
                _atmbFinal.SetExceptionOrResult(error, false);
                _tsEmitting.SetResult(false);
                break;

            case _sAccepting:
                Current = default;
                _state  = _sFinal;
                _ctr.Dispose();
                _atmbFinal.SetExceptionOrResult(error, false);
                _tsAccepting.SetExceptionOrResult(error, false);
                break;

            default:     // _sFinal
                _state = state;
                break;
            }
        }
Esempio n. 30
0
 protected override void algorithm()
 {
     result = 0;
     Parallel.For(ExecuteOn, 0, sizeX, delegate(int x){
         Atomic.Add(ref result, a[x]);
     });
 }
Esempio n. 31
0
        private static void ThreadFunc(object state)
        {
            int index = (int)state;

            ThreadContext.Set((index + ThreadCount).ToString(), index);
            Atomic.Inc(ref lock_);

            while (Atomic.Cas(ref lock_, ThreadCount, ThreadCount) != ThreadCount)
            {
                Soyo.Base.Thread.Sleep(1);
            }

            bool result = ThreadContext.Contains("1");

            Assert.IsFalse(result, "value should be false");;

            result = ThreadContext.Contains("2");
            Assert.IsFalse(result, "value should be false");;

            for (int i = 0; i < ThreadCount; i++)
            {
                object value = ThreadContext.Get((i + ThreadCount).ToString());
                if (i == index)
                {
                    Assert.AreEqual(value, index, "value should be index");
                }
                else
                {
                    Assert.IsNull(value, "value should be null");;
                }
                Atomic.Inc(ref checkCount_);
            }
        }
Esempio n. 32
0
 public void ShouldTryAndUpdate()
 {
     var atomic = new Atomic<int>(100);
     const int expected = 110;
     bool success = atomic.TryUpdate(expected);
     Assert.True(success);
     Assert.AreEqual(expected, atomic.Value);
 }
Esempio n. 33
0
 public void ShouldTryAndUpdateUsingFunction()
 {
     var atomic = new Atomic<int>(0);
     const int expected = 100;
     bool success = atomic.TryUpdate(x => x + expected);
     Assert.True(success);
     Assert.AreEqual(expected, atomic.Value);
 }
 public void Atomic_Long_Load_Should_Success()
 {
     var atomicLong = new Atomic<long>(long.MaxValue);
     Assert.Equal(long.MaxValue, atomicLong.Load(MemoryOrder.Relaxed));
     Assert.Equal(long.MaxValue, atomicLong.Load(MemoryOrder.Acquire));
     Assert.Equal(long.MaxValue, atomicLong.Load(MemoryOrder.AcqRel));
     Assert.Equal(long.MaxValue, atomicLong.Load(MemoryOrder.SeqCst));
 }
Esempio n. 35
0
 public void ShouldUpdateUsingFunction()
 {
     var atomic = new Atomic<int>();
     const int expected = 100;
     int actual = atomic.Update(x => x + expected);
     Assert.AreEqual(expected, actual);
     Assert.AreEqual(expected, atomic.Value);
 }
Esempio n. 36
0
        public void ParameterlessConstructorShouldInitDefaultValue()
        {
            var atomicString = new Atomic<string>();
            Assert.IsNull(atomicString.Value);

            var atomicInt = new Atomic<int>();
            Assert.AreEqual(0, atomicInt.Value);
        }
 public void Atomic_Int_Load_Should_Success()
 {
     var atomicInteger = new Atomic<int>(int.MaxValue);
     Assert.Equal(int.MaxValue, atomicInteger.Load(MemoryOrder.Relaxed));
     Assert.Equal(int.MaxValue, atomicInteger.Load(MemoryOrder.Acquire));
     Assert.Equal(int.MaxValue, atomicInteger.Load(MemoryOrder.AcqRel));
     Assert.Equal(int.MaxValue, atomicInteger.Load(MemoryOrder.SeqCst));
 }
Esempio n. 38
0
        public void ConstructorShouldSetSpecifiedValue()
        {
            const string atomicStringValue = "this is atomic value";
            var atomicString = new Atomic<string>(atomicStringValue);
            Assert.AreEqual(atomicStringValue, atomicString.Value);

            const int atomicIntValue = 100;
            var atomicInt = new Atomic<int>(atomicIntValue);
            Assert.AreEqual(atomicIntValue, atomicInt.Value);
        }
Esempio n. 39
0
 public void ShouldCallUpdateFunction()
 {
     bool called = false;
     var atomic = new Atomic<int>(100);
     atomic.Update(x =>
         {
             called = true;
             return x;
         });
     Assert.True(called);
 }
Esempio n. 40
0
 public void ConcurrentUpdateShouldFail()
 {
     var atomic = new Atomic<int>();
     var result = false;
     atomic.Update(x =>
         {
             var thread = new Thread(() => result = atomic.TryUpdate(100));
             thread.Start();
             return x;
         });
     Assert.False(result);
 }
Esempio n. 41
0
 public EpisState(Atomic[] atomicsName, bool[] atomicsPositivity)
 {
     _expressionContext = new ExpressionContext(this);
     if (atomicsName.Count() == atomicsPositivity.Count())
     {
         _status = new Dictionary<Atomic, bool>();
         for (int i = 0; i < atomicsName.Count(); i++)
         {
             _status.Add(atomicsName[i] , atomicsPositivity[i]);
         }
     }
 }
Esempio n. 42
0
 public IEnumerable<Solution> Search(Atomic atomic, bool verify = true) {
   IEnumerable<Solution> enumerable;
   switch (_activeStrategy) {
     case Strategy.Bfs:
       enumerable = BreadthFirstSeach.Search(atomic, verify);
       break;
     case Strategy.Dfs:
       enumerable = DepthFirstSeach.Search(atomic, verify);
       break;
     default:
       enumerable = BreadthFirstSeach.Search(atomic, verify);
       break;
   }
   // return a fresh copy of the atomic
   foreach (var item in enumerable) {
     yield return new Solution(item.State.Copy());
   }
 }
Esempio n. 43
0
    public FreshNameAtomic(Atomic atomic) : base(atomic) {

    }
Esempio n. 44
0
 public GenBexpAtomic(Atomic atomic) : base(atomic) { }
Esempio n. 45
0
 public IdAtomic(Atomic atomic) : base(atomic) { }
Esempio n. 46
0
 protected BlockAtomic(Atomic atomic) : base(atomic) { }
Esempio n. 47
0
    private Solution LazyScanMemberBody(MemberDecl md) {
      Contract.Requires(md != null);
      Console.WriteLine($"Starting thread: {System.Threading.Thread.CurrentThread.Name}");
      Debug.WriteLine($"Scanning member {md.Name} body");
      var function = md as Function;
      if (function != null) {
        var fun = function;
        if (fun.Body == null)
          return null;
        var expt = ExpressionTree.ExpressionToTree(fun.Body);
        expt.FindAndResolveTacticApplication(_tacnyProgram, fun);
        /* No reason ot generate new solution
         * if nothing has been changed 
         */
        if (!expt.Modified)
          return null;
        var res = expt.TreeToExpression();
        var newFun = new Function(fun.tok, fun.Name, fun.HasStaticKeyword, fun.IsProtected, fun.IsGhost, fun.TypeArgs, fun.Formals, fun.ResultType, fun.Req, fun.Reads, fun.Ens, fun.Decreases, res, fun.Attributes, fun.SignatureEllipsis);
        var ac = new Atomic {
          IsFunction = true,
          DynamicContext = { newTarget = newFun }
        };
        return new Solution(ac);

      }
      var m = md as Method;
      if (m?.Body == null)
        return null;

      List<IVariable> variables = new List<IVariable>();
      List<IVariable> resolved;
      lock (_tacnyProgram) {
       resolved = _tacnyProgram.GetResolvedVariables(md);
      }
      variables.AddRange(m.Ins);
      variables.AddRange(m.Outs);
      resolved.AddRange(m.Ins); // add input arguments as resolved variables
      resolved.AddRange(m.Outs);
      // does not work for multiple tactic applications
      foreach (var st in m.Body.Body) {
        UpdateStmt us = null;
        WhileStmt ws = null;
        // register local variables
        if (st is VarDeclStmt) {
          VarDeclStmt vds = st as VarDeclStmt;
          variables.AddRange(vds.Locals);
        } else if (st is UpdateStmt) {
          us = st as UpdateStmt;
        } else if (st is WhileStmt) {
          ws = st as WhileStmt;
          us = ws.TacAps as UpdateStmt;
          foreach (var wst in ws.Body.Body) {
            if (!(wst is VarDeclStmt)) continue;
            var vds = wst as VarDeclStmt;
            variables.AddRange(vds.Locals);
          }
        }
        if (us == null || !_tacnyProgram.IsTacticCall(us)) continue;
        Debug.WriteLine("Tactic call found");
        return ResolveTactic(variables, resolved, us, md, ws);
      }
      return null;
    }
Esempio n. 48
0
 public DeleteAtomic(Atomic atomic) : base(atomic) { }
Esempio n. 49
0
 public MergeAtomic(Atomic atomic) : base(atomic) { }
 public OutboundMessagePipeline(IPipelineSink<ISendContext> output)
 {
     _output = Atomic.Create(output);
 }
Esempio n. 51
0
 public ExpressionAtomic(Atomic atomic) : base(atomic) { }
Esempio n. 52
0
 public FailAtomic(Atomic atomic) : base(atomic) { }
Esempio n. 53
0
 public PredicateAtomic(Atomic atomic) : base(atomic) { }
Esempio n. 54
0
 public void ShouldUpdateValue()
 {
     var atomic = new Atomic<int>(100);
     const int expected = 110;
     int actual = atomic.Update(expected);
     Assert.AreEqual(expected, actual);
 }
Esempio n. 55
0
 public ParamsAtomic(Atomic atomic) : base(atomic) { }
Esempio n. 56
0
 public ReturnAtomic(Atomic atomic) : base(atomic) { }
Esempio n. 57
0
 public VariantAtomic(Atomic atomic) : base(atomic) { }
Esempio n. 58
0
 public SolvedAtomic(Atomic atomic) : base(atomic) { }
Esempio n. 59
0
 public ChangedAtomic(Atomic atomic) : base(atomic) { }
Esempio n. 60
0
 public VariablesAtomic(Atomic atomic) : base(atomic) { }