MAsync(System.Byte[] p_0)
        {
            SerializableTaskCompletionSource rpcTask;
            // Make call, wait for reply
            // Compute size of serialized arguments
            var totalArgSize = 0;
            int arg0Size     = 0;

            byte[] arg0Bytes = null;

            // Argument 0
            arg0Bytes = p_0;
            arg0Size  = IntSize(arg0Bytes.Length) + arg0Bytes.Length;

            totalArgSize += arg0Size;

            var wp           = this.StartRPC <object>(methodIdentifier: 1 /* method identifier for M */, lengthOfSerializedArguments: totalArgSize, taskToWaitFor: out rpcTask);
            var asyncContext = new AsyncContext {
                SequenceNumber = Immortal.CurrentSequenceNumber
            };

            // Serialize arguments


            // Serialize arg0
            wp.curLength += wp.PageBytes.WriteInt(wp.curLength, arg0Bytes.Length);
            Buffer.BlockCopy(arg0Bytes, 0, wp.PageBytes, wp.curLength, arg0Bytes.Length);
            wp.curLength += arg0Bytes.Length;

            int taskId;

            lock (Immortal.DispatchTaskIdQueueLock)
            {
                while (!Immortal.DispatchTaskIdQueue.Data.TryDequeue(out taskId))
                {
                }
            }

            ReleaseBufferAndSend();

            Immortal.StartDispatchLoop();

            var taskToWaitFor = Immortal.CallCache.Data[asyncContext.SequenceNumber].GetAwaitableTaskWithAdditionalInfoAsync();
            var currentResult = await taskToWaitFor;

            while (currentResult.AdditionalInfoType != ResultAdditionalInfoTypes.SetResult)
            {
                switch (currentResult.AdditionalInfoType)
                {
                case ResultAdditionalInfoTypes.SaveContext:
                    await Immortal.SaveTaskContextAsync();

                    taskToWaitFor = Immortal.CallCache.Data[asyncContext.SequenceNumber].GetAwaitableTaskWithAdditionalInfoAsync();
                    break;

                case ResultAdditionalInfoTypes.TakeCheckpoint:
                    var sequenceNumber = await Immortal.TakeTaskCheckpointAsync();

                    Immortal.StartDispatchLoop();
                    taskToWaitFor = Immortal.GetTaskToWaitForWithAdditionalInfoAsync(sequenceNumber);
                    break;
                }

                currentResult = await taskToWaitFor;
            }

            lock (Immortal.DispatchTaskIdQueueLock)
            {
                Immortal.DispatchTaskIdQueue.Data.Enqueue(taskId);
            }
            return;
        }
Exemple #2
0
 private void Expand()
 {
   var newBuffer = new byte[BufferSize * 2];
   Buffer.BlockCopy(m_Buffer, 0, newBuffer, 0, m_Buffer.Length);
   m_Buffer = newBuffer;
 }
Exemple #3
0
 public MessageBuffer(byte[] data)
 {
     mBuffer = new byte[data.Length];
     Buffer.BlockCopy(data, 0, mBuffer, 0, data.Length);
 }