public static LzmaResult lzma_stream_encoder_mt(ref LzmaStream stream, ref LzmaMT mt) { if (SupportsMultiThreading) { return(lzma_stream_encoder_mt_ptr(ref stream, ref mt)); } else { throw new PlatformNotSupportedException("lzma_stream_encoder_mt is not supported on this platform. Check SupportsMultiThreading to see whether you can use this functionality."); } }
public XZOutputStream(Stream stream, int threads, uint preset, bool leaveOpen) { if (stream == null) { throw new ArgumentNullException(nameof(stream)); } this.innerStream = stream; this.leaveOpen = leaveOpen; LzmaResult ret; if (threads == 1 || !NativeMethods.SupportsMultiThreading) { ret = NativeMethods.lzma_easy_encoder(ref this.lzmaStream, preset, LzmaCheck.Crc64); } else { if (threads <= 0) { throw new ArgumentOutOfRangeException(nameof(threads)); } if (threads > Environment.ProcessorCount) { Trace.TraceWarning("{0} threads required, but only {1} processors available", threads, Environment.ProcessorCount); threads = Environment.ProcessorCount; } var mt = new LzmaMT() { preset = preset, check = LzmaCheck.Crc64, threads = (uint)threads, }; ret = NativeMethods.lzma_stream_encoder_mt(ref this.lzmaStream, ref mt); } if (ret == LzmaResult.OK) { this.outbuf = new byte[BufSize]; this.lzmaStream.AvailOut = BufSize; return; } GC.SuppressFinalize(this); LzmaException.ThrowOnError(ret); }