/// <summary> /// 添加任务 /// </summary> /// <param name="value"></param> internal void Add(LinkQueueTaskNode value) { while (System.Threading.Interlocked.CompareExchange(ref queueLock, 1, 0) != 0) { AutoCSer.Threading.ThreadYield.Yield(AutoCSer.Threading.ThreadYield.Type.SqlLinkQueueTaskPush); } if (head == null) { head = end = value; } else { end.LinkNext = value; end = value; } queueLock = 0; if (System.Threading.Interlocked.CompareExchange(ref isThread, 1, 0) == 0) { try { threadPool.FastStart(run); } catch (Exception error) { AutoCSer.Log.Pub.Log.Add(Log.LogType.Error, error); run(); } } }
/// <summary> /// 添加任务 /// </summary> /// <param name="value"></param> internal void Add(LinkQueueTaskNode value) { queueLock.EnterYield(); if (head == null) { head = end = value; } else { end.LinkNext = value; end = value; } queueLock.Exit(); if (System.Threading.Interlocked.CompareExchange(ref isThread, 1, 0) == 0) { try { threadPool.FastStart(run); } catch (Exception error) { AutoCSer.LogHelper.Exception(error, null, LogLevel.Exception | LogLevel.AutoCSer); run(); } } }
private void run() { START: DbConnection connection = null; do { while (System.Threading.Interlocked.CompareExchange(ref queueLock, 1, 0) != 0) { AutoCSer.Threading.ThreadYield.Yield(AutoCSer.Threading.ThreadYield.Type.SqlLinkQueueTaskPop); } LinkQueueTaskNode value = head; head = end = null; queueLock = 0; if (value == null) { System.Threading.Thread.Sleep(0); while (System.Threading.Interlocked.CompareExchange(ref queueLock, 1, 0) != 0) { AutoCSer.Threading.ThreadYield.Yield(AutoCSer.Threading.ThreadYield.Type.SqlLinkQueueTaskPop); } value = head; head = end = null; queueLock = 0; if (value == null) { client.FreeConnection(ref connection); //isThread = 0; System.Threading.Interlocked.Exchange(ref isThread, 0); if (head != null && System.Threading.Interlocked.CompareExchange(ref isThread, 1, 0) == 0) { goto START; } return; } } do { try { do { value = value.RunLinkQueueTask(ref connection); }while (value != null); break; } catch (Exception error) { client.CloseErrorConnection(ref connection); AutoCSer.Log.Pub.Log.Add(Log.LogType.Error, error); } LinkQueueTaskNode next = value.LinkNext; value.LinkNext = null; value = next; }while (value != null); }while (true); }
private void run() { START: DbConnection connection = null; do { queueLock.EnterYield(); LinkQueueTaskNode value = head; head = end = null; queueLock.Exit(); if (value == null) { System.Threading.Thread.Sleep(0); queueLock.EnterYield(); value = head; head = end = null; queueLock.Exit(); if (value == null) { client.FreeConnection(ref connection); //isThread = 0; System.Threading.Interlocked.Exchange(ref isThread, 0); if (head != null && System.Threading.Interlocked.CompareExchange(ref isThread, 1, 0) == 0) { goto START; } return; } } do { try { do { value.RunLinkQueueTask(ref connection, ref value); }while (value != null); break; } catch (Exception error) { client.ResetErrorConnection(ref connection); AutoCSer.LogHelper.Exception(error, null, LogLevel.Exception | LogLevel.AutoCSer); } }while (value != null); }while (true); }