| 68 | std::atomic<bool> Terminate; |
| 69 | |
| 70 | static void DoWork(int threadIndex, vtkWorkQueue* self) |
| 71 | { |
| 72 | vtkLogger::SetThreadName("Worker " + vtk::to_string(threadIndex)); |
| 73 | vtkLogF(TRACE, "starting worker thread"); |
| 74 | vtkNew<vtkJPEGWriter> writer; |
| 75 | writer->WriteToMemoryOn(); |
| 76 | while (!self->Terminate) |
| 77 | { |
| 78 | vtkWork work; |
| 79 | { |
| 80 | std::unique_lock<std::mutex> lock(self->QueueMutex); |
| 81 | bool break_loop = false; |
| 82 | do |
| 83 | { |
| 84 | self->QueueCondition.wait_for(lock, std::chrono::seconds(1), |
| 85 | [self]() { return !self->Queue.empty() || self->Terminate; }); |
| 86 | if (self->Terminate) |
| 87 | { |
| 88 | break_loop = true; |
| 89 | break; |
| 90 | } |
| 91 | } while (self->Queue.empty()); |
| 92 | if (break_loop) |
| 93 | { |
| 94 | break; |
| 95 | } |
| 96 | work = self->Queue.front(); |
| 97 | self->Queue.pop(); |
| 98 | } |
| 99 | |
| 100 | writer->SetInputData(work.Image); |
| 101 | writer->SetQuality(work.Quality); |
| 102 | writer->Write(); |
| 103 | |
| 104 | auto result = vtkSmartPointer<vtkUnsignedCharArray>::New(); |
| 105 | if (work.Encoding) |
| 106 | { |
| 107 | vtkUnsignedCharArray* data = writer->GetResult(); |
| 108 | result->SetNumberOfComponents(1); |
| 109 | result->SetNumberOfTuples(std::ceil(1.5 * data->GetNumberOfTuples())); |
| 110 | unsigned long size = vtkBase64Utilities::Encode( |
| 111 | data->GetPointer(0), data->GetNumberOfTuples(), result->GetPointer(0), /*mark_end=*/0); |
| 112 | result->SetNumberOfTuples(static_cast<vtkIdType>(size) + 1); |
| 113 | result->SetValue(size, 0); |
| 114 | } |
| 115 | else |
| 116 | { |
| 117 | // We must do a deep copy here as the writer reuse that array |
| 118 | // and will change its values concurrently during its next job... |
| 119 | result->DeepCopy(writer->GetResult()); |
| 120 | } |
| 121 | writer->SetInputData(nullptr); |
| 122 | |
| 123 | { |
| 124 | std::unique_lock<std::mutex> lock(self->ResultsMutex); |
| 125 | auto& pair = self->Results[work.Key]; |
| 126 | if (pair.first < work.TimeStamp) |
| 127 | { |
nothing calls this directly
no test coverage detected