| 121 | } |
| 122 | |
| 123 | void S3KeyWriter::flushBuffer() { |
| 124 | if (!this->buffer.empty()) { |
| 125 | UniqueLock queueLock(&this->mutex); |
| 126 | while (this->activeThreads >= this->params.getNumOfChunks()) { |
| 127 | pthread_cond_wait(&this->cv, &this->mutex); |
| 128 | } |
| 129 | |
| 130 | // Most time query is canceled during uploadPartOfData(). This is the first chance to cancel |
| 131 | // and clean up upload. |
| 132 | this->checkQueryCancelSignal(); |
| 133 | |
| 134 | this->activeThreads++; |
| 135 | |
| 136 | pthread_t writerThread; |
| 137 | ThreadParams* params = new ThreadParams(); |
| 138 | params->keyWriter = this; |
| 139 | params->data.swap(this->buffer); |
| 140 | params->currentNumber = ++this->partNumber; |
| 141 | pthread_create(&writerThread, NULL, UploadThreadFunc, params); |
| 142 | threadList.emplace_back(writerThread); |
| 143 | |
| 144 | this->buffer.reserve(this->params.getChunkSize()); |
| 145 | } |
| 146 | } |
| 147 | |
| 148 | void S3KeyWriter::completeKeyWriting() { |
| 149 | // make sure the buffer is clear |
no test coverage detected