Run the provided work item and wait up to 'timeout_milliseconds' for the operation to complete. If it completes, return the status from the work item's Execute() function. Otherwise, return an error status: - THREAD_POOL_TASK_TIMED_OUT if the individual task timed out - THREAD_POOL_SUBMIT_FAILED if all the threads are busy and the task did not even start
| 321 | /// - THREAD_POOL_SUBMIT_FAILED if all the threads are busy and the task did not |
| 322 | /// even start |
| 323 | Status SynchronousOffer(std::shared_ptr<SynchronousWorkItem> work, |
| 324 | int64_t timeout_milliseconds) { |
| 325 | MonotonicStopWatch offer_timer; |
| 326 | offer_timer.Start(); |
| 327 | bool offer_success = Offer(work, timeout_milliseconds); |
| 328 | offer_timer.Stop(); |
| 329 | if (!offer_success) { |
| 330 | // This scenario only happens when all threads are occupied and the queue |
| 331 | // is full. This means the system is in a catastrophic state. Log to ERROR. |
| 332 | Status failed_to_submit_status = |
| 333 | Status(TErrorCode::THREAD_POOL_SUBMIT_FAILED, work->GetDescription(), |
| 334 | timeout_milliseconds / MILLIS_PER_SEC); |
| 335 | LOG(ERROR) << failed_to_submit_status.GetDetail(); |
| 336 | return failed_to_submit_status; |
| 337 | } |
| 338 | |
| 339 | int64_t time_used_millis = |
| 340 | offer_timer.ElapsedTime() / (NANOS_PER_MICRO * MICROS_PER_MILLI); |
| 341 | return work->Wait(timeout_milliseconds, time_used_millis); |
| 342 | } |
| 343 | |
| 344 | private: |
| 345 | static void Worker(int thread_id, const std::shared_ptr<SynchronousWorkItem>& work) { |