| 9 | #include <chrono> |
| 10 | |
| 11 | WriterThread::WriterThread(Options* opt, string filename, bool isSTDOUT){ |
| 12 | mOptions = opt; |
| 13 | mWriter1 = NULL; |
| 14 | mInputCompleted = false; |
| 15 | mFilename = filename; |
| 16 | |
| 17 | mPwriteMode = !isSTDOUT && ends_with(filename, ".gz") && mOptions->thread > 1; |
| 18 | mFd = -1; |
| 19 | mOffsetRing = NULL; |
| 20 | mNextSeq = NULL; |
| 21 | mCompressors = NULL; |
| 22 | mCompBufs = NULL; |
| 23 | mCompBufSizes = NULL; |
| 24 | mBufferLists = NULL; |
| 25 | |
| 26 | if (mPwriteMode) { |
| 27 | mFd = open(mFilename.c_str(), O_WRONLY | O_CREAT | O_TRUNC, 0644); |
| 28 | if (mFd < 0) |
| 29 | error_exit("Failed to open for pwrite: " + mFilename); |
| 30 | mOffsetRing = new OffsetSlot[OFFSET_RING_SIZE]; |
| 31 | mNextSeq = new size_t[mOptions->thread]; |
| 32 | for (int t = 0; t < mOptions->thread; t++) |
| 33 | mNextSeq[t] = t; |
| 34 | mCompressors = new libdeflate_compressor*[mOptions->thread]; |
| 35 | for (int t = 0; t < mOptions->thread; t++) |
| 36 | mCompressors[t] = libdeflate_alloc_compressor(mOptions->compression); |
| 37 | size_t initBufSize = PACK_SIZE * 500; |
| 38 | mCompBufs = new char*[mOptions->thread]; |
| 39 | mCompBufSizes = new size_t[mOptions->thread]; |
| 40 | for (int t = 0; t < mOptions->thread; t++) { |
| 41 | mCompBufs[t] = new char[initBufSize]; |
| 42 | mCompBufSizes[t] = initBufSize; |
| 43 | } |
| 44 | mWorkingBufferList = 0; |
| 45 | mBufferLength = 0; |
| 46 | } else { |
| 47 | initWriter(filename, isSTDOUT); |
| 48 | initBufferLists(); |
| 49 | mWorkingBufferList = 0; |
| 50 | mBufferLength = 0; |
| 51 | } |
| 52 | } |
| 53 | |
| 54 | WriterThread::~WriterThread() { |
| 55 | cleanup(); |
nothing calls this directly
no test coverage detected