Esempio n. 1
0
        private unsafe static void _reader(int totalChunks, readFunc rf)
        {
            byte *buffer = stackalloc byte[maxPacketSize];

            Interlocked.Increment(ref threadsStarted);

            SpinWait sw     = new SpinWait();
            int      readed = 0;

            while (Volatile.Read(ref threadsStarted) != Volatile.Read(ref nThreads) + 1)
            {
                sw.SpinOnce();
            }

            while (chunksReaded != totalChunks)
            {
                Span <byte> span = rf(out bool success, buffer);

                if (!success)
                {
                    sw.SpinOnce();
                    continue;
                }

                readed = span.Length;

                if (rf == readStream)
                {
                    if (!verifyPacket(buffer, readed))
                    {
                        Console.WriteLine("ERROR!");
                        Environment.Exit(-1);
                    }
                }
                else
                {
                    fixed(byte *bfRef = &MemoryMarshal.GetReference(span))
                    if (!verifyPacket(bfRef, readed))
                    {
                        Console.WriteLine("ERROR!");
                        Environment.Exit(-1);
                    }
                }
                chunksReaded++;
                totalBytesReaded += readed;
            }
        }
Esempio n. 2
0
        static bool cpImage(Tiff inImage, Tiff outImage, readFunc fin, writeFunc fout, int imagelength, int imagewidth, short spp)
        {
            bool status = false;

            int scanlinesize = inImage.RasterScanlineSize();
            int bytes = scanlinesize * imagelength;

            /*
             * XXX: Check for integer overflow.
             */
            if (scanlinesize != 0 && imagelength != 0 && (bytes / imagelength == scanlinesize))
            {
                byte[] buf = new byte[bytes];
                if (fin(inImage, buf, imagelength, imagewidth, spp))
                    status = fout(outImage, buf, imagelength, imagewidth, spp);
            }
            else
            {
                Tiff.Error(inImage.FileName(), "Error, no space for image buffer");
            }

            return status;
        }