Пример #1
0
 public static void FatalAssert(bool isOk, string message = "")
 {
     if (isOk == false)
     {
         CoreException.Throw(message);
     }
 }
Пример #2
0
            public int EmitNodsIndex;            // where in m_nodEmits to start looking

            public DynamicOrder OrderAgainst(object other)
            {
                var ot     = (ItemInfo)other;
                var aOrder = Item.ScheduleAgainst(ot.Item);
                var bOrder = ot.Item.ScheduleAgainst(Item);

                aOrder = ScheduleOrderUtil.ResolveOrder(aOrder, bOrder, out var conflict);
                if (conflict)
                {
                    CoreException.Throw("Bad dynamic order");
                }

                if (aOrder == ScheduleOrder.RunBefore)
                {
                    return(DynamicOrder.RequireABeforeB);
                }
                if (aOrder == ScheduleOrder.RunAfter)
                {
                    return(DynamicOrder.RequireBBeforeA);
                }

                // ok, soft order by hint
                var diff = (int)Item.Hint - (int)ot.Item.Hint;

                if (diff > 0)
                {
                    return(DynamicOrder.PreferBBeforeA);
                }
                if (diff < 0)
                {
                    return(DynamicOrder.PreferABeforeB);
                }
                return(DynamicOrder.AnyOrder);
            }
Пример #3
0
        private void VerifyIndex(int index)
        {
#if DEBUG
            if (index < 0 || index >= m_exactSize)
            {
                CoreException.Throw("Index out of range");
            }
#endif
        }
Пример #4
0
        public DynamicScheduler(ReadOnlySpan <TItem> scheduleItems)
        {
            var items = scheduleItems.ToArray();

            m_itemStatus = new ItemStatus[items.Length];
            m_order      = new ScheduleOrder[items.Length * items.Length];

            Array.Sort(items, (a, b) =>
            {
                int aval = (int)a.Hint;
                int bval = (int)b.Hint;
                if (aval > bval)
                {
                    return(1);
                }
                if (aval < bval)
                {
                    return(-1);
                }
                return(0);
            });

            // create matrices
            for (int a = 0; a < items.Length; a++)
            {
                for (int b = 0; b < items.Length; b++)
                {
                    if (a == b)
                    {
                        continue;
                    }

                    var order         = items[a].ScheduleAgainst(items[b]);
                    var antiorder     = items[b].ScheduleAgainst(items[a]);
                    var resolvedOrder = ResolveOrder(order, antiorder, out bool conflict);
                    if (conflict)
                    {
                        CoreException.Throw("Clashing schedule; {items[a].Item.ToString()} and {items[b].Item.ToString()} both wants to run " + order);
                    }
                    m_order[a * items.Length + b] = resolvedOrder;
                }
            }

            m_items = items;
        }
Пример #5
0
        public static void Assert(bool isOk, string message = "")
        {
            if (isOk == false)
            {
#if DEBUG
                if (Debugger.IsAttached)
                {
                    Debugger.Break();
                }
                else
                {
                    CoreException.Throw(message);
                }
#else
                CoreException.Throw(message);
#endif
            }
        }
Пример #6
0
        /// <summary>
        /// Compare content of two streams; buffers must be equal length and multiple of 8
        /// </summary>
        public static Result AreEqual(Stream fs1, Stream fs2, Span <byte> buf1, Span <byte> buf2)
        {
            CoreException.Assert(buf1.Length == buf2.Length);
            CoreException.Assert((buf1.Length & 7) == 0);

            ReadOnlySpan <ulong> ulBuf1 = MemoryMarshal.Cast <byte, ulong>(buf1);
            ReadOnlySpan <ulong> ulBuf2 = MemoryMarshal.Cast <byte, ulong>(buf2);

            for (; ;)
            {
                int len = fs1.Read(buf1);
                if (len < 1)
                {
                    return(Result.Identical);
                }

                int len2 = fs2.Read(buf2.Slice(0, len));

                if (len != len2)
                {
                    CoreException.Throw("Failed to read part of file");
                }

                if (len == buf1.Length)
                {
                    // compare ulongs
                    if (ulBuf1.SequenceEqual(ulBuf2) == false)
                    {
                        return(Result.Different);
                    }
                }
                else
                {
                    // compare bytes
                    if (buf1.Slice(0, len).SequenceEqual(buf2.Slice(0, len)) == false)
                    {
                        return(Result.Different);
                    }
                }
            }
        }
Пример #7
0
        public DynamicScheduler(ReadOnlySpan <TItem> scheduleItems)
        {
            m_executeItemAction = ExecuteScheduledItem;

            var items = new ItemInfo[scheduleItems.Length];

            for (int i = 0; i < items.Length; i++)
            {
                items[i] = new ItemInfo()
                {
                    Item = scheduleItems[i]
                }
            }
            ;

            // sort dynamically
            var ok = DynamicOrdering.Perform <ItemInfo>(items, out _);

            if (!ok)
            {
                CoreException.Throw("Failed to sort dynamically");
            }

            m_concurrencyPreventionMatrix = new SymmetricMatrixBool(scheduleItems.Length);
            m_running = new FastList <ItemInfo>(16);

            // set up items (determine nods, concurrency etc)
            var nods = new FastList <int>(32);

            for (int aIdx = 0; aIdx < items.Length; aIdx++)
            {
                var a = items[aIdx];
                a.Index = aIdx;                 // set up index
                ref var aInfo = ref items[aIdx];
                aInfo.EmitNodsIndex = nods.Count;
                for (int bIdx = 0; bIdx < items.Length; bIdx++)
                {
                    if (aIdx == bIdx)
                    {
                        continue;
                    }

                    // determine is aIdx nods to bIdx
                    var b      = items[bIdx];
                    var aOrder = a.Item.ScheduleAgainst(b.Item);
                    var bOrder = b.Item.ScheduleAgainst(a.Item);
                    aOrder = ScheduleOrderUtil.ResolveOrder(aOrder, bOrder, out var conflict);
                    if (aOrder == ScheduleOrder.RunBefore)
                    {
                        ref var bInfo = ref items[bIdx];
                        bInfo.NodsRequired++;
                        nods.Add(bIdx);
                    }

                    if (aOrder != ScheduleOrder.AnyOrderConcurrent)
                    {
                        m_concurrencyPreventionMatrix[aIdx, bIdx] = true;
                    }
                }
                aInfo.EmitNodsCount = nods.Count - aInfo.EmitNodsIndex;
            }