| 1063 | } |
| 1064 | |
| 1065 | bool Process() { |
| 1066 | std::lock_guard<std::mutex> guard(gate_); |
| 1067 | if (!CheckEnded()) { |
| 1068 | return false; |
| 1069 | } |
| 1070 | |
| 1071 | // Process batches while we have data |
| 1072 | for (;;) { |
| 1073 | Result<std::shared_ptr<RecordBatch>> result = ProcessInner(); |
| 1074 | |
| 1075 | if (result.ok()) { |
| 1076 | auto out_rb = *result; |
| 1077 | if (!out_rb) break; |
| 1078 | ExecBatch out_b(*out_rb); |
| 1079 | out_b.index = batches_produced_++; |
| 1080 | DEBUG_SYNC(this, "produce batch ", out_b.index, ":", DEBUG_MANIP(std::endl), |
| 1081 | out_rb->ToString(), DEBUG_MANIP(std::endl)); |
| 1082 | Status st = output_->InputReceived(this, std::move(out_b)); |
| 1083 | if (!st.ok()) { |
| 1084 | EndFromProcessThread(std::move(st)); |
| 1085 | } |
| 1086 | } else { |
| 1087 | EndFromProcessThread(result.status()); |
| 1088 | return false; |
| 1089 | } |
| 1090 | } |
| 1091 | |
| 1092 | // Report to the output the total batch count, if we've already finished everything |
| 1093 | // (there are two places where this can happen: here and InputFinished) |
| 1094 | // |
| 1095 | // It may happen here in cases where InputFinished was called before we were finished |
| 1096 | // producing results (so we didn't know the output size at that time) |
| 1097 | if (!CheckEnded()) { |
| 1098 | return false; |
| 1099 | } |
| 1100 | |
| 1101 | // There is no more we can do now but there is still work remaining for later when |
| 1102 | // more data arrives. |
| 1103 | return true; |
| 1104 | } |
| 1105 | |
| 1106 | void ProcessThread() { |
| 1107 | for (;;) { |
nothing calls this directly
no test coverage detected