private unsafe static void _sender(int packetsToSend, writeFunc wf) { byte *buffer = stackalloc byte[maxPacketSize]; Random rnd = new Random((int)(Environment.TickCount + (int)DateTime.Now.Ticks)); Interlocked.Increment(ref threadsStarted); SpinWait sw = new SpinWait(); while (Volatile.Read(ref threadsStarted) != Volatile.Read(ref nThreads) + 1) { sw.SpinOnce(); } for (int i = 0; i < packetsToSend; ++i) { makePacket(buffer, out int packetsSize, rnd); // приходится делать .ToArray() из-за совместимости с очередью wf(new Span <byte>(buffer, packetsSize).ToArray(), packetsSize); Interlocked.Increment(ref chunksSended); Interlocked.Add(ref totalBytesSended, packetsSize); } }
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; }