/// <summary>
 /// 添加计算任务
 /// </summary>
 /// <param name="value"></param>
 internal void Append(ref ClientCustomSerialize value)
 {
     if (Interlocked.CompareExchange(ref isOutput, 1, 0) == 0)
     {
         append(ref value);
         onCustomSerialize.Callback(new ServerCustomSerialize {
             Output = this
         });
     }
     else
     {
         append(ref value);
         if (Interlocked.CompareExchange(ref isOutput, 1, 0) == 0)
         {
             if (headBuffer == null && currentBuffer == null)
             {
                 Interlocked.Exchange(ref isOutput, 0);
             }
             else
             {
                 onCustomSerialize.Callback(new ServerCustomSerialize {
                     Output = this
                 });
             }
         }
     }
 }
Beispiel #2
0
        /// <summary>
        /// 添加计算任务
        /// </summary>
        /// <param name="value"></param>
        private void append(ref ClientCustomSerialize value)
        {
            int length = value.Buffer.Count;
            ServerCustomSerializeBuffer buffer = null;

            while (System.Threading.Interlocked.CompareExchange(ref bufferLock, 1, 0) != 0)
            {
                AutoCSer.Threading.ThreadYield.Yield();
            }
            if (currentBuffer != null)
            {
                if (currentBuffer.Size + length <= ServerCustomSerializeBuffer.BufferSize)
                {
                    buffer = currentBuffer;
                }
                else
                {
                    if (endBuffer == null)
                    {
                        headBuffer = currentBuffer;
                    }
                    else
                    {
                        endBuffer.LinkNext = currentBuffer;
                    }
                    endBuffer = currentBuffer;
                }
                currentBuffer = null;
            }
            System.Threading.Interlocked.Exchange(ref bufferLock, 0);
            if (buffer == null)
            {
                while (System.Threading.Interlocked.CompareExchange(ref freeBufferLock, 1, 0) != 0)
                {
                    AutoCSer.Threading.ThreadYield.Yield();
                }
                if (freeBuffer == null)
                {
                    System.Threading.Interlocked.Exchange(ref freeBufferLock, 0);
                    buffer = new ServerCustomSerializeBuffer();
                }
                else
                {
                    buffer     = freeBuffer;
                    freeBuffer = freeBuffer.LinkNext;
                    System.Threading.Interlocked.Exchange(ref freeBufferLock, 0);
                    buffer.LinkNext = null;
                }
            }
            buffer.Copy(ref value.Buffer);
            while (System.Threading.Interlocked.CompareExchange(ref bufferLock, 1, 0) != 0)
            {
                AutoCSer.Threading.ThreadYield.Yield();
            }
            currentBuffer = buffer;
            System.Threading.Interlocked.Exchange(ref bufferLock, 0);
        }
Beispiel #3
0
 private unsafe void addCustomSerializeRegister(ClientCustomSerialize value)
 {
     fixed(byte *bufferFixed = value.Buffer.BufferArray)
     {
         for (byte *read = bufferFixed + value.Buffer.StartIndex, end = read + value.Buffer.Count; read != end; read += sizeof(int) * 2)
         {
             onAdd(new Add(*(int *)read, *(int *)(read + sizeof(int))));
         }
     }
 }
Beispiel #4
0
        /// <summary>
        /// 添加计算任务
        /// </summary>
        /// <param name="value"></param>
        private void append(ref ClientCustomSerialize value)
        {
            int length = value.Buffer.Count;
            ServerCustomSerializeBuffer buffer = null;

            AutoCSer.Threading.Interlocked.CompareExchangeYield(ref bufferLock);
            if (currentBuffer != null)
            {
                if (currentBuffer.Size + length <= ServerCustomSerializeBuffer.BufferSize)
                {
                    buffer = currentBuffer;
                }
                else
                {
                    if (endBuffer == null)
                    {
                        headBuffer = currentBuffer;
                    }
                    else
                    {
                        endBuffer.LinkNext = currentBuffer;
                    }
                    endBuffer = currentBuffer;
                }
                currentBuffer = null;
            }
            bufferLock = 0;
            if (buffer == null)
            {
                AutoCSer.Threading.Interlocked.CompareExchangeYield(ref freeBufferLock);
                if (freeBuffer == null)
                {
                    freeBufferLock = 0;
                    buffer         = new ServerCustomSerializeBuffer();
                }
                else
                {
                    buffer          = freeBuffer;
                    freeBuffer      = freeBuffer.LinkNext;
                    freeBufferLock  = 0;
                    buffer.LinkNext = null;
                }
            }
            buffer.Copy(ref value.Buffer);
            AutoCSer.Threading.Interlocked.CompareExchangeYield(ref bufferLock);
            currentBuffer = buffer;
            bufferLock    = 0;
        }
Beispiel #5
0
 private void addCustomSerialize(ClientCustomSerialize value)
 {
     customSerializeOutput.Append(ref value);
 }
 /// <summary>
 /// 计算回调测试
 /// </summary>
 /// <param name="value"></param>
 public void AddCustomSerialize(ClientCustomSerialize value)
 {
     customSerializeOutput.Append(ref value);
 }