/// <summary> /// 添加节点 /// </summary> /// <param name="value"></param> internal void PushNotNull(valueType value) { if (count >= maxCount) { if (isDisponse) { ((IDisposable)value).Dispose(); } return; } System.Threading.Interlocked.Increment(ref count); valueType headValue; do { if ((headValue = head) == null) { value.LinkNext = null; if (System.Threading.Interlocked.CompareExchange(ref head, value, null) == null) { return; } } else { value.LinkNext = headValue; if (System.Threading.Interlocked.CompareExchange(ref head, value, headValue) == headValue) { return; } } ThreadYield.Yield(ThreadYield.Type.YieldLinkPush); }while (true); }
public static void CompareExchangeYield(ref int value) { while (System.Threading.Interlocked.CompareExchange(ref value, 1, 0) != 0) { ThreadYield.Yield(ThreadYield.Type.Unknown); } }
/// <summary> /// 弹出节点 /// </summary> /// <returns></returns> public valueType Pop() { valueType headValue; while (System.Threading.Interlocked.CompareExchange(ref popLock, 1, 0) != 0) { AutoCSer.Threading.ThreadYield.Yield(AutoCSer.Threading.ThreadYield.Type.YieldLinkPop); } do { if ((headValue = head) == null) { System.Threading.Interlocked.Exchange(ref popLock, 0); return(null); } if (System.Threading.Interlocked.CompareExchange(ref head, headValue.LinkNext, headValue) == headValue) { System.Threading.Interlocked.Exchange(ref popLock, 0); System.Threading.Interlocked.Decrement(ref count); headValue.LinkNext = null; return(headValue); } ThreadYield.Yield(ThreadYield.Type.YieldLinkPop); }while (true); }
/// <summary> /// 添加链表 /// </summary> /// <param name="value">链表头部</param> /// <param name="end">链表尾部</param> /// <param name="count">数据数量</param> internal void PushLink(valueType value, valueType end, int count) { System.Threading.Interlocked.Add(ref this.count, count); valueType headValue; do { if ((headValue = head) == null) { end.LinkNext = null; if (System.Threading.Interlocked.CompareExchange(ref head, value, null) == null) { return; } } else { end.LinkNext = headValue; if (System.Threading.Interlocked.CompareExchange(ref head, value, headValue) == headValue) { return; } } ThreadYield.Yield(ThreadYield.Type.YieldLinkPush); }while (true); }
/// <summary> /// 添加节点 /// </summary> /// <param name="value"></param> /// <returns></returns> internal int IsPushNotNull(valueType value) { if (count >= maxCount) { return(0); } System.Threading.Interlocked.Increment(ref count); valueType headValue; do { if ((headValue = head) == null) { value.LinkNext = null; if (System.Threading.Interlocked.CompareExchange(ref head, value, null) == null) { return(1); } } else { value.LinkNext = headValue; if (System.Threading.Interlocked.CompareExchange(ref head, value, headValue) == headValue) { return(1); } } ThreadYield.Yield(ThreadYield.Type.YieldLinkPush); }while (true); }
internal void PushNotNull(valueType value) { valueType headValue; do { if ((headValue = head) == null) { value.LinkNext = null; if (System.Threading.Interlocked.CompareExchange(ref head, value, null) == null) { return; } } else { value.LinkNext = headValue; if (System.Threading.Interlocked.CompareExchange(ref head, value, headValue) == headValue) { return; } } ThreadYield.Yield(ThreadYield.Type.YieldLinkPush); }while (true); }
internal void PushLink(T value, T end) { T headValue; do { if ((headValue = Head) == null) { end.LinkNext = null; if (System.Threading.Interlocked.CompareExchange(ref Head, value, null) == null) { return; } } else { end.LinkNext = headValue; if (System.Threading.Interlocked.CompareExchange(ref Head, value, headValue) == headValue) { return; } } ThreadYield.Yield(); }while (true); }
public valueType SinglePop() { valueType headValue; do { if ((headValue = head) == null) { return(null); } if (System.Threading.Interlocked.CompareExchange(ref head, headValue.LinkNext, headValue) == headValue) { headValue.LinkNext = null; return(headValue); } ThreadYield.Yield(ThreadYield.Type.YieldLinkPop); }while (true); }
public T SinglePop() { T headValue; do { if ((headValue = Head) == null) { return(null); } if (System.Threading.Interlocked.CompareExchange(ref Head, headValue.LinkNext, headValue) == headValue) { headValue.LinkNext = null; return(headValue); } ThreadYield.Yield(); }while (true); }