コード例 #1
0
ファイル: FasterLog.cs プロジェクト: mito-csod/FASTER
        /// <summary>
        /// Try to enqueue entry to log (in memory). If it returns true, we are
        /// done. If it returns false, we need to retry.
        /// </summary>
        /// <param name="entry">Entry to be enqueued to log</param>
        /// <param name="logicalAddress">Logical address of added entry</param>
        /// <returns>Whether the append succeeded</returns>
        public unsafe bool TryEnqueue(byte[] entry, out long logicalAddress)
        {
            logicalAddress = 0;

            epoch.Resume();

            var length = entry.Length;

            logicalAddress = allocator.TryAllocate(headerSize + Align(length));
            if (logicalAddress == 0)
            {
                epoch.Suspend();
                return(false);
            }

            var physicalAddress = allocator.GetPhysicalAddress(logicalAddress);

            fixed(byte *bp = entry)
            Buffer.MemoryCopy(bp, (void *)(headerSize + physicalAddress), length, length);

            SetHeader(length, (byte *)physicalAddress);
            epoch.Suspend();
            return(true);
        }