コード例 #1
0
        private void PartitionWorkItemQueue(BsnesImportStreamProcessor.CompressedWorkItem compressedItem)
        {
            Debug.Assert(compressedItem.wasDecompressed);

            using var stream = new MemoryStream(compressedItem.UncompressedBuffer, 0, compressedItem.UncompressedSize);
            compressedItem.tmpHeader ??= new byte[2];

            // tune this as needed.
            // we want parallel jobs going, but, we don't want too many of them at once.
            // average # workItems per CompressedWorkItem is like 12K currently.
            const int numItemsPerTask = 6000;
            bool      keepGoing;
            var       itemsRemainingBeforeEnd = numItemsPerTask;

            Debug.Assert(compressedItem.listHeads != null && compressedItem.listHeads.Count == 0);

            BsnesImportStreamProcessor.WorkItem currentHead = null;
            BsnesImportStreamProcessor.WorkItem currentItem = null;

            do
            {
                var nextItem = ReadNextWorkItem(stream, compressedItem.tmpHeader);

                if (nextItem != null)
                {
                    Debug.Assert(nextItem.next == null);

                    if (currentHead == null)
                    {
                        currentHead = nextItem;
                        Debug.Assert(currentItem == null);
                    }
                    else
                    {
                        currentItem.next = nextItem;
                    }
                    currentItem = nextItem;

                    itemsRemainingBeforeEnd--;
                }

                keepGoing = !streamProcessor.CancelToken.IsCancellationRequested && nextItem != null;
                var endOfPartition = !keepGoing || itemsRemainingBeforeEnd == 0;
                if (!endOfPartition)
                {
                    continue;
                }

                // finish list
                if (currentHead != null)
                {
                    Debug.Assert(currentItem.next == null);
                    compressedItem.listHeads.Add(currentHead);
                }

                // reset list
                currentHead             = currentItem = null;
                itemsRemainingBeforeEnd = numItemsPerTask;
            } while (keepGoing);
        }
コード例 #2
0
        private void ProcessWorkItem(BsnesImportStreamProcessor.WorkItem workItem)
        {
            #if PROFILING
            var mainSpan = Markers.EnterSpan("BSNES ProcessWorkItem");
            #endif

            // this importer call is thread-safe, so we don't need to do our own locking
            importer.ImportTraceLogLineBinary(workItem.Buffer, workItem.Format);

#if PROFILING
            mainSpan.Leave();
            #endif
        }
コード例 #3
0
 private void ProcessWorkItem(BsnesImportStreamProcessor.WorkItem workItem)
 {
     try
     {
         // definitely hitting lock contention.
         importerLock.EnterWriteLock();
         importer.ImportTraceLogLineBinary(workItem.Buffer, workItem.AbridgedFormat);
     }
     finally
     {
         importerLock.ExitWriteLock();
     }
 }
コード例 #4
0
        private void ProcessWorkItemsLinkedList(BsnesImportStreamProcessor.WorkItem workItemListHead)
        {
            #if PROFILING
            var mainSpan = Markers.EnterSpan("BSNES ProcessWorkItems");
            #endif

            // iterate linked list
            var current = workItemListHead;
            while (current != null)
            {
                ProcessWorkItem(current);
                var next = current.next;
                streamProcessor.FreeWorkItem(ref current);

                current = next;
            }

            #if PROFILING
            mainSpan.Leave();
            #endif
        }