| 526 | |
| 527 | template <typename TaskType> |
| 528 | Status Queue<TaskType>::Schedule(std::unique_ptr<TaskType>* task) { |
| 529 | if ((*task)->size() > options_.max_batch_size) { |
| 530 | return errors::InvalidArgument("Task size ", (*task)->size(), |
| 531 | " is larger than maximum batch size ", |
| 532 | options_.max_batch_size); |
| 533 | } |
| 534 | |
| 535 | bool notify_of_schedulable_batch = false; |
| 536 | { |
| 537 | mutex_lock l(mu_); |
| 538 | |
| 539 | DCHECK(!closed_); |
| 540 | |
| 541 | if (batches_.back()->size() + (*task)->size() > options_.max_batch_size) { |
| 542 | if (batches_.size() >= options_.max_enqueued_batches) { |
| 543 | return errors::Unavailable( |
| 544 | "The batch scheduling queue to which this task was submitted is " |
| 545 | "full"); |
| 546 | } |
| 547 | StartNewBatch(); |
| 548 | } |
| 549 | if (batches_.back()->empty()) { |
| 550 | open_batch_start_time_micros_ = env_->NowMicros(); |
| 551 | } |
| 552 | batches_.back()->AddTask(std::move(*task)); |
| 553 | |
| 554 | if (!schedulable_batch_) { |
| 555 | if (batches_.size() > 1 || IsOpenBatchSchedulable()) { |
| 556 | schedulable_batch_ = true; |
| 557 | notify_of_schedulable_batch = true; |
| 558 | } |
| 559 | } |
| 560 | } |
| 561 | |
| 562 | if (notify_of_schedulable_batch) { |
| 563 | schedulable_batch_callback_(); |
| 564 | } |
| 565 | |
| 566 | return Status::OK(); |
| 567 | } |
| 568 | |
| 569 | template <typename TaskType> |
| 570 | size_t Queue<TaskType>::NumEnqueuedTasks() const { |
nothing calls this directly
no test coverage detected