iceberg-cpp
Loading...
Searching...
No Matches
executor.h
1/*
2 * Licensed to the Apache Software Foundation (ASF) under one
3 * or more contributor license agreements. See the NOTICE file
4 * distributed with this work for additional information
5 * regarding copyright ownership. The ASF licenses this file
6 * to you under the Apache License, Version 2.0 (the
7 * "License"); you may not use this file except in compliance
8 * with the License. You may obtain a copy of the License at
9 *
10 * http://www.apache.org/licenses/LICENSE-2.0
11 *
12 * Unless required by applicable law or agreed to in writing,
13 * software distributed under the License is distributed on an
14 * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
15 * KIND, either express or implied. See the License for the
16 * specific language governing permissions and limitations
17 * under the License.
18 */
19
20#pragma once
21
22#include <atomic>
23#include <thread>
24#include <utility>
25#include <vector>
26
27#include "iceberg/result.h"
28#include "iceberg/util/executor.h"
29
30namespace iceberg::test {
31
32class ThreadExecutor final : public Executor {
33 public:
34 explicit ThreadExecutor(Status submit_status = {})
35 : submit_status_(std::move(submit_status)) {}
36
37 ~ThreadExecutor() override {
38 for (auto& thread : threads_) {
39 if (thread.joinable()) {
40 thread.join();
41 }
42 }
43 }
44
45 Status Submit(ExecutorTask task) override {
46 submit_count_.fetch_add(1, std::memory_order_relaxed);
47 if (!submit_status_.has_value()) {
48 return std::unexpected(submit_status_.error());
49 }
50 threads_.emplace_back(std::move(task));
51 return {};
52 }
53
54 int submit_count() const { return submit_count_.load(std::memory_order_relaxed); }
55
56 private:
57 Status submit_status_;
58 std::atomic<int> submit_count_{0};
59 std::vector<std::thread> threads_;
60};
61
62} // namespace iceberg::test
Schedules iceberg-cpp internal planning tasks.
Definition executor.h:43
Definition functional.h:45
Definition executor.h:32
Status Submit(ExecutorTask task) override
Schedule a task for execution.
Definition executor.h:45