System.Threading.Interlocked.CompareExchange(ref T, T, T)

Here are the examples of the csharp api System.Threading.Interlocked.CompareExchange(ref T, T, T) taken from open source projects. By voting up you can indicate which examples are most useful and appropriate.

520 Examples 7

19 View Source File : MethodDef.cs
License : GNU General Public License v3.0
Project Creator : anydream

protected virtual void InitializeParamDefs() {
			Interlocked.CompareExchange(ref paramDefs, new LazyList<ParamDef>(this), null);
		}

19 View Source File : AssemblyDef.cs
License : GNU General Public License v3.0
Project Creator : anydream

protected override void InitializeCustomAttributes() {
			var list = readerModule.MetaData.GetCustomAttributeRidList(Table.replacedembly, origRid);
			var tmp = new CustomAttributeCollection((int)list.Length, list, (list2, index) => readerModule.ReadCustomAttribute(((RidList)list2)[index]));
			Interlocked.CompareExchange(ref customAttributes, tmp, null);
		}

19 View Source File : SwitchMap.cs
License : Apache License 2.0
Project Creator : akarnokd

void DrainLoop()
            {
                var missed = 1;
                var delayErrors = this.delayErrors;
                var downstream = this.downstream;


                for (; ;)
                {
                    for (; ; )
                    {
                        var a = Volatile.Read(ref active);

                        if (a == DISPOSED)
                        {
                            break;
                        }

                        if (!delayErrors)
                        {
                            var ex = Volatile.Read(ref errors);
                            if (ex != null)
                            {
                                downstream.OnError(ex);
                                Dispose();
                                break;
                            }
                        }

                        bool d = Volatile.Read(ref done);

                        if (d && a == null)
                        {
                            var ex = ExceptionHelper.Terminate(ref errors);
                            if (ex == null)
                            {
                                downstream.OnCompleted();
                            }
                            else
                            {
                                downstream.OnError(ex);
                            }
                            Dispose();
                            break;
                        }

                        if (a == null)
                        {
                            break;
                        }

                        var innerDone = a.IsDone();
                        var q = a.GetQueue();
                        var v = default(R);
                        var empty = true;

                        if (q != null)
                        {
                            v = q.TryPoll(out var success);
                            empty = !success;
                        }

                        if (innerDone && empty)
                        {
                            Interlocked.CompareExchange(ref active, null, a);
                        }
                        else
                        if (empty)
                        {
                            break;
                        }
                        else
                        {
                            downstream.OnNext(v);
                        }
                    }

                    missed = Interlocked.Add(ref wip, -missed);
                    if (missed == 0)
                    {
                        break;
                    }
                }
            }

19 View Source File : ParamDef.cs
License : GNU General Public License v3.0
Project Creator : anydream

protected override void InitializeCustomAttributes() {
			var list = readerModule.MetaData.GetCustomAttributeRidList(Table.Param, origRid);
			var tmp = new CustomAttributeCollection((int)list.Length, list, (list2, index) => readerModule.ReadCustomAttribute(((RidList)list2)[index]));
			Interlocked.CompareExchange(ref customAttributes, tmp, null);
		}

19 View Source File : SingleExecutorService.cs
License : Apache License 2.0
Project Creator : akarnokd

public void Start()
        {
            SingleThreadedExecutor ys = null;
            for (;;)
            {
                var xs = Volatile.Read(ref executor);
                if (xs != null)
                {
                    break;
                }
                if (ys == null)
                {
                    ys = new SingleThreadedExecutor(name + "-" + (Interlocked.Increment(ref index)));
                }
                if (Interlocked.CompareExchange(ref executor, ys, xs) == xs)
                {
                    break;
                }
            }
        }

19 View Source File : RedoWhenSignalObserver.cs
License : Apache License 2.0
Project Creator : akarnokd

internal void HandleSignal(X signal)
        {
            for (; ; )
            {
                var d = Volatile.Read(ref upstream);
                if (d != DisposableHelper.DISPOSED && Interlocked.CompareExchange(ref upstream, null, d) == d)
                {
                    d.Dispose();
                    terminalSignal.OnNext(signal);
                    break;
                }
            }
        }

19 View Source File : TypeRef.cs
License : GNU General Public License v3.0
Project Creator : anydream

protected override void InitializeCustomAttributes() {
			var list = readerModule.MetaData.GetCustomAttributeRidList(Table.TypeRef, origRid);
			var tmp = new CustomAttributeCollection((int)list.Length, list, (list2, index) => readerModule.ReadCustomAttribute(((RidList)list2)[index]));
			Interlocked.CompareExchange(ref customAttributes, tmp, null);
		}

19 View Source File : SwitchIfEmpty.cs
License : Apache License 2.0
Project Creator : akarnokd

internal void Next(IObservable<T> first)
            {
                if (Interlocked.Increment(ref wip) == 1)
                {
                    do
                    {
                        var sad = new SinglereplacedignmentDisposable();
                        if (Interlocked.CompareExchange(ref upstream, sad, null) == null)
                        {
                            if (first != null)
                            {
                                sad.Disposable = first.Subscribe(this);
                                first = null;
                            }
                            else
                            {
                                if (index == fallbacks.Length)
                                {
                                    downstream.OnCompleted();
                                } else
                                {
                                    var src = fallbacks[index];
                                    if (src != null)
                                    {
                                        fallbacks[index] = null;

                                        index++;
                                        sad.Disposable = src.Subscribe(this);
                                    }
                                    else
                                    {
                                        downstream.OnError(new NullReferenceException("The fallbacks[" + index + "] is null"));
                                    }
                                }
                            }
                        }
                    }
                    while (Interlocked.Decrement(ref wip) != 0);
                }
            }

19 View Source File : FieldDef.cs
License : GNU General Public License v3.0
Project Creator : anydream

protected override void InitializeCustomAttributes() {
			var list = readerModule.MetaData.GetCustomAttributeRidList(Table.Field, origRid);
			var tmp = new CustomAttributeCollection((int)list.Length, list, (list2, index) => readerModule.ReadCustomAttribute(((RidList)list2)[index]));
			Interlocked.CompareExchange(ref customAttributes, tmp, null);
		}

19 View Source File : ObservableSourcePublish.cs
License : Apache License 2.0
Project Creator : akarnokd

public IDisposable Connect(Action<IDisposable> onConnect = null)
        {
            for (; ; )
            {
                var subject = Volatile.Read(ref connection);
                if (subject == null)
                {
                    subject = new PublishSubject<T>();
                    if (Interlocked.CompareExchange(ref connection, subject, null) != null)
                    {
                        continue;
                    }
                }
                else
                {
                    if (subject.HasException() || subject.HasCompleted() || subject.IsDisposed())
                    {
                        Interlocked.CompareExchange(ref connection, null, subject);
                        continue;
                    }
                }

                var shouldConnect = subject.Prepare();

                onConnect?.Invoke(subject);

                if (shouldConnect)
                {
                    source.Subscribe(subject);
                }

                return subject;
            }
        }

19 View Source File : ManifestResource.cs
License : GNU General Public License v3.0
Project Creator : anydream

protected override void InitializeCustomAttributes() {
			var list = readerModule.MetaData.GetCustomAttributeRidList(Table.ManifestResource, origRid);
			var tmp = new CustomAttributeCollection((int)list.Length, list, (list2, index) => readerModule.ReadCustomAttribute(((RidList)list2)[index]));
			Interlocked.CompareExchange(ref customAttributes, tmp, null);
		}

19 View Source File : SubscriptionHelper.cs
License : Apache License 2.0
Project Creator : akarnokd

internal static bool DeferredSetOnce(ref ISubscription subscription, ref long requested, ISubscription next)
        {
            if (next == null)
            {
                throw new ArgumentNullException(nameof(next));
            }
            if (Interlocked.CompareExchange(ref subscription, next, null) == null)
            {
                long r = Interlocked.Exchange(ref requested, 0L);
                if (r != 0L)
                {
                    next.Request(r);
                }
                return true;
            }
            next.Cancel();
            return false;
        }

19 View Source File : ObservableSourceSwitchMap.cs
License : Apache License 2.0
Project Creator : akarnokd

public override void OnNext(T value)
            {
                if (done)
                {
                    return;
                }

                var o = default(IObservableSource<R>);

                try
                {
                    o = ValidationHelper.RequireNonNullRef(mapper(value), "The mapper returned a null IObservableSource");
                }
                catch (Exception ex)
                {
                    OnError(ex);
                    return;
                }

                var inner = new InnerSignalObserver<R>(this);

                for (; ; )
                {
                    var a = Volatile.Read(ref active);
                    if (a == DISPOSED)
                    {
                        break;
                    }

                    if (Interlocked.CompareExchange(ref active, inner, a) == a)
                    {
                        a?.Dispose();

                        o.Subscribe(inner);
                        break;
                    }
                }
            }

19 View Source File : EventDef.cs
License : GNU General Public License v3.0
Project Creator : anydream

protected override void InitializeCustomAttributes() {
			var list = readerModule.MetaData.GetCustomAttributeRidList(Table.Event, origRid);
			var tmp = new CustomAttributeCollection((int)list.Length, list, (list2, index) => readerModule.ReadCustomAttribute(((RidList)list2)[index]));
			Interlocked.CompareExchange(ref customAttributes, tmp, null);
		}

19 View Source File : RetryPredicate.cs
License : Apache License 2.0
Project Creator : akarnokd

public override void OnError(Exception error)
            {
                var again = false;

                try
                {
                    again = predicate(error, ++count);
                }
                catch (Exception ex)
                {
                    downstream.OnError(new AggregateException(error, ex));
                    Dispose();
                    return;
                }
                if (again)
                {
                    var d = Volatile.Read(ref upstream);
                    if (d != DisposableHelper.DISPOSED)
                    {
                        if (Interlocked.CompareExchange(ref upstream, null, d) == d)
                        {
                            d?.Dispose();
                            Next();
                        }
                    }
                }
                else
                {
                    downstream.OnError(error);
                    Dispose();
                }
            }

19 View Source File : MethodDef.cs
License : GNU General Public License v3.0
Project Creator : anydream

protected override void InitializeParamDefs() {
			var list = readerModule.MetaData.GetParamRidList(origRid);
			var tmp = new LazyList<ParamDef>((int)list.Length, this, list, (list2, index) => readerModule.ResolveParam(((RidList)list2)[index]));
			Interlocked.CompareExchange(ref paramDefs, tmp, null);
		}

19 View Source File : ConcatMany.cs
License : Apache License 2.0
Project Creator : akarnokd

internal bool SetDisposable(SinglereplacedignmentDisposable sad)
                {
                    return Interlocked.CompareExchange(ref upstream, sad, null) == null;
                }

19 View Source File : AssemblyDef.cs
License : GNU General Public License v3.0
Project Creator : anydream

protected virtual void InitializeModules() {
			Interlocked.CompareExchange(ref modules, new LazyList<ModuleDef>(this), null);
		}

19 View Source File : SystemMonitor.cs
License : Mozilla Public License 2.0
Project Creator : agebullhu

private static void worker_sound_off()
        {
            //SystemManage对象重启时机
            if (Interlocked.CompareExchange(ref ZeroApplication._appState, StationState.Start, StationState.Failed) == StationState.Failed)
            {
                ZeroApplication.JoinCenter();
                return;
            }

            if (ZeroApplication.InRun)
                ZeroApplication.OnHeartbeat();
        }

19 View Source File : ExportedType.cs
License : GNU General Public License v3.0
Project Creator : anydream

protected override void InitializeCustomAttributes() {
			var list = readerModule.MetaData.GetCustomAttributeRidList(Table.ExportedType, origRid);
			var tmp = new CustomAttributeCollection((int)list.Length, list, (list2, index) => readerModule.ReadCustomAttribute(((RidList)list2)[index]));
			Interlocked.CompareExchange(ref customAttributes, tmp, null);
		}

19 View Source File : ConnectableFlowableMulticast.cs
License : Apache License 2.0
Project Creator : akarnokd

public void Reset()
        {
            var p = Volatile.Read(ref processor);
            if (p.HasComplete || p.HasException || p.IsDisposed)
            {
                var q = processorSupplier();
                Interlocked.CompareExchange(ref processor, q, p);
                Interlocked.CompareExchange(ref connected, null, p);
            }
        }

19 View Source File : ConnectableFlowableMulticast.cs
License : Apache License 2.0
Project Creator : akarnokd

public IDisposable Connect(Action<IDisposable> onConnect = null)
        {
            for (;;)
            {
                var p = Volatile.Read(ref connected);
                if (p == null || p.HasException || p.HasComplete || p.IsDisposed)
                {
                    var u = Volatile.Read(ref processor);
                    if (u.HasComplete || u.HasException || u.IsDisposed)
                    {
                        var q = processorSupplier();
                        if (Interlocked.CompareExchange(ref processor, q, u) == u)
                        {
                            if (Interlocked.CompareExchange(ref connected, q, p) == p)
                            {
                                onConnect?.Invoke(q);
                                source.Subscribe(q);
                                return q;
                            }
                        }
                    }
                    else
                    {
                        if (Interlocked.CompareExchange(ref connected, u, p) == p)
                        {
                            onConnect?.Invoke(u);
                            source.Subscribe(u);
                            return u;
                        }
                    }
                }
                else
                {
                    onConnect?.Invoke(p);
                    return p;
                }
            }
        }

19 View Source File : MaybeCache.cs
License : Apache License 2.0
Project Creator : akarnokd

public void Subscribe(IMaybeObserver<T> observer)
        {
            var parent = new CacheDisposable(observer, this);
            observer.OnSubscribe(parent);

            if (Add(parent))
            {
                if (parent.IsDisposed())
                {
                    Remove(parent);
                }
            }
            else
            {
                if (!parent.IsDisposed())
                {
                    var ex = error;
                    if (ex != null)
                    {
                        observer.OnError(ex);
                    }
                    else
                    {
                        if (hasValue)
                        {
                            observer.OnSuccess(value);
                        }
                        else
                        {
                            observer.OnCompleted();
                        }
                    }
                }
                return;
            }

            var src = Volatile.Read(ref source);
            if (src != null && Interlocked.CompareExchange(ref source, null, src) == src)
            {
                var c = cancel;
                cancel = null;

                try
                {
                    c?.Invoke(this);
                }
                catch (Exception ex)
                {
                    OnError(ex);
                    return;
                }

                src.Subscribe(this);
            }
        }

19 View Source File : SubscriptionHelper.cs
License : Apache License 2.0
Project Creator : akarnokd

internal static bool SetOnce(ref ISubscription subscription, ISubscription next, bool crash = true)
        {
            if (next == null)
            {
                throw new ArgumentNullException(nameof(next));
            }
            ISubscription current = Interlocked.CompareExchange(ref subscription, next, null);
            if (current == null)
            {
                return true;
            }
            next?.Cancel();
            if (current != Cancelled)
            {
                var e = new InvalidOperationException("ISubscription already set!");
                if (crash)
                {
                    throw e;
                }
                else
                {
                    System.Diagnostics.Debug.WriteLine(e.ToString());
                }
            }
            return false;
        }

19 View Source File : ObservableSourcePublish.cs
License : Apache License 2.0
Project Creator : akarnokd

public void Reset()
        {
            var subject = Volatile.Read(ref connection);
            if (subject != null) {
                if (subject.HasException() || subject.HasCompleted() || subject.IsDisposed())
                {
                    Interlocked.CompareExchange(ref connection, null, subject);
                }
            }
        }

19 View Source File : InterfaceImpl.cs
License : GNU General Public License v3.0
Project Creator : anydream

protected override void InitializeCustomAttributes() {
			var list = readerModule.MetaData.GetCustomAttributeRidList(Table.InterfaceImpl, origRid);
			var tmp = new CustomAttributeCollection((int)list.Length, list, (list2, index) => readerModule.ReadCustomAttribute(((RidList)list2)[index]));
			Interlocked.CompareExchange(ref customAttributes, tmp, null);
		}

19 View Source File : MetaData.cs
License : GNU General Public License v3.0
Project Creator : anydream

void InitializeNestedClreplacedesDictionary() {
			var table = tablesStream.NestedClreplacedTable;
			var destTable = tablesStream.TypeDefTable;

			Dictionary<uint, bool> validTypeDefRids = null;
			var typeDefRidList = GetTypeDefRidList();
			if (typeDefRidList.Length != destTable.Rows) {
				validTypeDefRids = new Dictionary<uint, bool>((int)typeDefRidList.Length);
				for (uint i = 0; i < typeDefRidList.Length; i++)
					validTypeDefRids[typeDefRidList[i]] = true;
			}

			var nestedRidsDict = new Dictionary<uint, bool>((int)table.Rows);
			var nestedRids = new List<uint>((int)table.Rows);	// Need it so we add the rids in correct order
			for (uint rid = 1; rid <= table.Rows; rid++) {
				if (validTypeDefRids != null && !validTypeDefRids.ContainsKey(rid))
					continue;
				var row = tablesStream.ReadNestedClreplacedRow(rid);
				if (row == null)
					continue;	// Should never happen since rid is valid
				if (!destTable.IsValidRID(row.NestedClreplaced) || !destTable.IsValidRID(row.EnclosingClreplaced))
					continue;
				if (nestedRidsDict.ContainsKey(row.NestedClreplaced))
					continue;
				nestedRidsDict[row.NestedClreplaced] = true;
				nestedRids.Add(row.NestedClreplaced);
			}

			var newTypeDefRidToNestedClreplacedes = new Dictionary<uint, RandomRidList>();
			foreach (var nestedRid in nestedRids) {
				var row = tablesStream.ReadNestedClreplacedRow(GetNestedClreplacedRid(nestedRid));
				if (row == null)
					continue;
				RandomRidList ridList;
				if (!newTypeDefRidToNestedClreplacedes.TryGetValue(row.EnclosingClreplaced, out ridList))
					newTypeDefRidToNestedClreplacedes[row.EnclosingClreplaced] = ridList = new RandomRidList();
				ridList.Add(nestedRid);
			}

			var newNonNestedTypes = new RandomRidList((int)(destTable.Rows - nestedRidsDict.Count));
			for (uint rid = 1; rid <= destTable.Rows; rid++) {
				if (validTypeDefRids != null && !validTypeDefRids.ContainsKey(rid))
					continue;
				if (nestedRidsDict.ContainsKey(rid))
					continue;
				newNonNestedTypes.Add(rid);
			}

			Interlocked.CompareExchange(ref nonNestedTypes, newNonNestedTypes, null);

			// Initialize this one last since it's tested by the callers of this method
			Interlocked.CompareExchange(ref typeDefRidToNestedClreplacedes, newTypeDefRidToNestedClreplacedes, null);
		}

19 View Source File : ObservableSourceReplay.cs
License : Apache License 2.0
Project Creator : akarnokd

public IDisposable Connect(Action<IDisposable> onConnect = null)
        {
            for (; ; )
            {
                var subject = Volatile.Read(ref connection);
                if (subject == null)
                {
                    subject = new CacheSubject<T>();
                    if (Interlocked.CompareExchange(ref connection, subject, null) != null)
                    {
                        continue;
                    }
                }
                else
                {
                    if (subject.HasException() || subject.HasCompleted() || subject.IsDisposed())
                    {
                        Interlocked.CompareExchange(ref connection, null, subject);
                        continue;
                    }
                }

                var shouldConnect = subject.Prepare();

                onConnect?.Invoke(subject);

                if (shouldConnect)
                {
                    source.Subscribe(subject);
                }

                return subject;
            }
        }

19 View Source File : ModuleRef.cs
License : GNU General Public License v3.0
Project Creator : anydream

protected override void InitializeCustomAttributes() {
			var list = readerModule.MetaData.GetCustomAttributeRidList(Table.ModuleRef, origRid);
			var tmp = new CustomAttributeCollection((int)list.Length, list, (list2, index) => readerModule.ReadCustomAttribute(((RidList)list2)[index]));
			Interlocked.CompareExchange(ref customAttributes, tmp, null);
		}

19 View Source File : RepeatPredicate.cs
License : Apache License 2.0
Project Creator : akarnokd

public override void OnCompleted()
            {
                var again = false;

                try
                {
                    again = predicate();
                }
                catch (Exception ex)
                {
                    downstream.OnError(ex);
                    Dispose();
                    return;
                }
                if (again)
                {
                    var d = Volatile.Read(ref upstream);
                    if (d != DisposableHelper.DISPOSED)
                    {
                        if (Interlocked.CompareExchange(ref upstream, null, d) == d)
                        {
                            d?.Dispose();
                            Next();
                        }
                    }
                }
                else
                {
                    downstream.OnCompleted();
                    Dispose();
                }
            }

19 View Source File : DeclSecurity.cs
License : GNU General Public License v3.0
Project Creator : anydream

protected override void InitializeCustomAttributes() {
			var list = readerModule.MetaData.GetCustomAttributeRidList(Table.DeclSecurity, origRid);
			var tmp = new CustomAttributeCollection((int)list.Length, list, (list2, index) => readerModule.ReadCustomAttribute(((RidList)list2)[index]));
			Interlocked.CompareExchange(ref customAttributes, tmp, null);
		}

19 View Source File : ObservableSourceSwitchMap.cs
License : Apache License 2.0
Project Creator : akarnokd

void DrainLoop()
            {
                var missed = 1;
                var delayErrors = this.delayErrors;
                var downstream = this.downstream;


                for (; ;)
                {
                    for (; ; )
                    {
                        var a = Volatile.Read(ref active);

                        if (a == DISPOSED)
                        {
                            break;
                        }

                        if (!delayErrors)
                        {
                            var ex = Volatile.Read(ref errors);
                            if (ex != null)
                            {
                                downstream.OnError(ex);
                                Dispose();
                                break;
                            }
                        }

                        bool d = Volatile.Read(ref done);

                        if (d && a == null)
                        {
                            var ex = ExceptionHelper.Terminate(ref errors);
                            if (ex == null)
                            {
                                downstream.OnCompleted();
                            }
                            else
                            {
                                downstream.OnError(ex);
                            }
                            Dispose();
                            break;
                        }

                        if (a == null)
                        {
                            break;
                        }

                        var innerDone = a.IsDone();
                        var q = a.GetQueue();
                        var v = default(R);
                        var empty = true;

                        if (q != null)
                        {
                            try
                            {
                                v = q.TryPoll(out var success);
                                empty = !success;
                            }
                            catch (Exception ex)
                            {
                                if (delayErrors)
                                {
                                    ExceptionHelper.AddException(ref errors, ex);
                                }
                                else
                                {
                                    Interlocked.CompareExchange(ref errors, ex, null);
                                }
                                innerDone = true;
                            }
                        }

                        if (innerDone && empty)
                        {
                            Interlocked.CompareExchange(ref active, null, a);
                        }
                        else
                        if (empty)
                        {
                            break;
                        }
                        else
                        {
                            downstream.OnNext(v);
                        }
                    }

                    missed = Interlocked.Add(ref wip, -missed);
                    if (missed == 0)
                    {
                        break;
                    }
                }
            }

19 View Source File : MemberRef.cs
License : GNU General Public License v3.0
Project Creator : anydream

protected override void InitializeCustomAttributes() {
			var list = readerModule.MetaData.GetCustomAttributeRidList(Table.MemberRef, origRid);
			var tmp = new CustomAttributeCollection((int)list.Length, list, (list2, index) => readerModule.ReadCustomAttribute(((RidList)list2)[index]));
			Interlocked.CompareExchange(ref customAttributes, tmp, null);
		}

19 View Source File : SystemMonitor.cs
License : Mozilla Public License 2.0
Project Creator : agebullhu

private static void center_closing(string content)
        {
            if (Interlocked.CompareExchange(ref ZeroApplication._appState, StationState.Closing, StationState.Run) == StationState.Run)
            {
                ZeroTrace.SystemLog("center_close", content);
                ZeroApplication.RaiseEvent(ZeroNetEventType.CenterSystemClosing);
                ZeroApplication.ZerCenterStatus = ZeroCenterState.Closed;
                ZeroApplication.OnZeroEnd();
                ZeroApplication.ApplicationState = StationState.Failed;
            }
        }

19 View Source File : MethodDef.cs
License : GNU General Public License v3.0
Project Creator : anydream

protected virtual void InitializeGenericParameters() {
			Interlocked.CompareExchange(ref genericParameters, new LazyList<GenericParam>(this), null);
		}

19 View Source File : SingleCache.cs
License : Apache License 2.0
Project Creator : akarnokd

public void Subscribe(ISingleObserver<T> observer)
        {
            var parent = new CacheDisposable(observer, this);
            observer.OnSubscribe(parent);

            if (Add(parent))
            {
                if (parent.IsDisposed())
                {
                    Remove(parent);
                }
            }
            else
            {
                if (!parent.IsDisposed())
                {
                    var ex = error;
                    if (ex != null)
                    {
                        observer.OnError(ex);
                    }
                    else
                    {
                        observer.OnSuccess(value);
                    }
                }
                return;
            }

            var src = Volatile.Read(ref source);
            if (src != null && Interlocked.CompareExchange(ref source, null, src) == src)
            {
                var c = cancel;
                cancel = null;

                try
                {
                    c?.Invoke(this);
                }
                catch (Exception ex)
                {
                    OnError(ex);
                    return;
                }

                src.Subscribe(this);
            }
        }

19 View Source File : PropertyDef.cs
License : GNU General Public License v3.0
Project Creator : anydream

protected override void InitializeCustomAttributes() {
			var list = readerModule.MetaData.GetCustomAttributeRidList(Table.Property, origRid);
			var tmp = new CustomAttributeCollection((int)list.Length, list, (list2, index) => readerModule.ReadCustomAttribute(((RidList)list2)[index]));
			Interlocked.CompareExchange(ref customAttributes, tmp, null);
		}

19 View Source File : SwitchIfEmpty.cs
License : Apache License 2.0
Project Creator : akarnokd

public override void OnCompleted()
            {
                if (nonEmpty)
                {
                    downstream.OnCompleted();
                    Dispose();
                }
                else
                {
                    var d = Volatile.Read(ref upstream);
                    if (d != DisposableHelper.DISPOSED)
                    {
                        if (Interlocked.CompareExchange(ref upstream, null, d) == d)
                        {
                            d?.Dispose();
                            Next(null);
                        }
                    }
                }
            }

19 View Source File : TypeSpec.cs
License : GNU General Public License v3.0
Project Creator : anydream

protected override void InitializeCustomAttributes() {
			var list = readerModule.MetaData.GetCustomAttributeRidList(Table.TypeSpec, origRid);
			var tmp = new CustomAttributeCollection((int)list.Length, list, (list2, index) => readerModule.ReadCustomAttribute(((RidList)list2)[index]));
			Interlocked.CompareExchange(ref customAttributes, tmp, null);
		}

19 View Source File : ConcatMany.cs
License : Apache License 2.0
Project Creator : akarnokd

internal bool Finish()
                {
                    var sad = Volatile.Read(ref upstream);
                    if (sad != DISPOSED)
                    {
                        if (Interlocked.CompareExchange(ref upstream, null, sad) == sad)
                        {
                            sad.Dispose();
                            return true;
                        }
                    }
                    return false;
                }

19 View Source File : AssemblyDef.cs
License : GNU General Public License v3.0
Project Creator : anydream

protected override void InitializeModules() {
			var list = readerModule.GetModuleRidList();
			var tmp = new LazyList<ModuleDef>((int)list.Length + 1, this, list, (list2, index) => {
				ModuleDef module;
				if (index == 0)
					module = readerModule;
				else
					module = readerModule.ReadModule(((RidList)list2)[index - 1], this);
				if (module == null)
					module = new ModuleDefUser("INVALID", Guid.NewGuid());
				module.replacedembly = this;
				return module;
			});
			Interlocked.CompareExchange(ref modules, tmp, null);
		}

19 View Source File : BlockTests.cs
License : MIT License
Project Creator : AElfProject

private Block CreateBlock(Hash preBlockHash, int chainId, long height)
        {
            Interlocked.CompareExchange(ref preBlockHash, Hash.Empty, null);

            var block = new Block(HashHelper.ComputeFrom("hash1"));

            block.Header.PreviousBlockHash = preBlockHash;
            block.Header.ChainId = chainId;
            block.Header.Time = TimestampHelper.GetUtcNow();
            block.Header.Height = height;
            var transactionItems = GenerateFakeTransactions(3);
            block.Body.TransactionIds.AddRange(transactionItems.Item2);

            block.Header.MerkleTreeRootOfTransactions =
                BinaryMerkleTree.FromLeafNodes(block.Body.TransactionIds).Root;
            block.Header.MerkleTreeRootOfWorldState = Hash.Empty;
            block.Header.MerkleTreeRootOfTransactionStatus = Hash.Empty;
            block.Header.SignerPubkey = ByteString.CopyFromUtf8("SignerPubkey");

            return block;
        }

19 View Source File : AssemblyRef.cs
License : GNU General Public License v3.0
Project Creator : anydream

protected override void InitializeCustomAttributes() {
			var list = readerModule.MetaData.GetCustomAttributeRidList(Table.replacedemblyRef, origRid);
			var tmp = new CustomAttributeCollection((int)list.Length, list, (list2, index) => readerModule.ReadCustomAttribute(((RidList)list2)[index]));
			Interlocked.CompareExchange(ref customAttributes, tmp, null);
		}

19 View Source File : ObservableSourceReplay.cs
License : Apache License 2.0
Project Creator : akarnokd

public void Subscribe(ISignalObserver<T> observer)
        {
            for (; ; )
            {
                var subject = Volatile.Read(ref connection);
                if (subject == null)
                {
                    subject = new CacheSubject<T>();
                    if (Interlocked.CompareExchange(ref connection, subject, null) != null)
                    {
                        continue;
                    }
                }

                subject.Subscribe(observer);

                break;
            }
        }

19 View Source File : SwitchMap.cs
License : Apache License 2.0
Project Creator : akarnokd

public override void OnNext(T value)
            {
                if (done)
                {
                    return;
                }

                var o = default(IObservable<R>);

                try
                {
                    o = mapper(value);
                    if (o == null)
                    {
                        throw new NullReferenceException("The mapper returned a null " + typeof(IObservable<R>));
                    }
                }
                catch (Exception ex)
                {
                    OnError(ex);
                    return;
                }

                var inner = new InnerObserver<R>(this);

                for (; ; )
                {
                    var a = Volatile.Read(ref active);
                    if (a == DISPOSED)
                    {
                        break;
                    }

                    if (Interlocked.CompareExchange(ref active, inner, a) == a)
                    {
                        a?.Dispose();

                        inner.OnSubscribe(o.Subscribe(inner));
                        break;
                    }
                }
            }

19 View Source File : PipelineTemplateSchemaFactory.cs
License : MIT License
Project Creator : actions

public static TemplateSchema GetSchema()
        {
            if (s_schema == null)
            {
                var replacedembly = replacedembly.GetExecutingreplacedembly();
                var json = default(String);
                using (var stream = replacedembly.GetManifestResourceStream("GitHub.DistributedTask.Pipelines.ObjectTemplating.workflow-v1.0.json"))
                using (var streamReader = new StreamReader(stream))
                {
                    json = streamReader.ReadToEnd();
                }

                var objectReader = new JsonObjectReader(null, json);
                var schema = TemplateSchema.Load(objectReader);
                Interlocked.CompareExchange(ref s_schema, schema, null);
            }

            return s_schema;
        }

19 View Source File : SystemMonitor.cs
License : Mozilla Public License 2.0
Project Creator : agebullhu

private static void center_start(string content)
        {
            if (Interlocked.CompareExchange(ref ZeroApplication._appState, StationState.Initialized, StationState.Failed) == StationState.Failed)
            {
                ZeroTrace.SystemLog("center_start", content);
                ZeroApplication.JoinCenter();
            }
        }

19 View Source File : RedoObserver.cs
License : Apache License 2.0
Project Creator : akarnokd

internal void Next()
        {
            if (Interlocked.Increment(ref wip) != 1)
            {
                return;
            }

            for (; ; )
            {
                var sad = new SinglereplacedignmentDisposable();
                if (Interlocked.CompareExchange(ref upstream, sad, null) == null)
                {
                    sad.Disposable = source.Subscribe(this);
                }

                if (Interlocked.Decrement(ref wip) == 0)
                {
                    break;
                }
            }
        }

19 View Source File : ObservableSourcePublish.cs
License : Apache License 2.0
Project Creator : akarnokd

public void Subscribe(ISignalObserver<T> observer)
        {
            for (; ; )
            {
                var subject = Volatile.Read(ref connection);
                if (subject == null)
                {
                    subject = new PublishSubject<T>();
                    if (Interlocked.CompareExchange(ref connection, subject, null) != null)
                    {
                        continue;
                    }
                }

                subject.Subscribe(observer);

                break;
            }
        }

19 View Source File : EventDef.cs
License : GNU General Public License v3.0
Project Creator : anydream

protected virtual void InitializeCustomAttributes() {
			Interlocked.CompareExchange(ref customAttributes, new CustomAttributeCollection(), null);
		}

See More Examples