1*6fa2df46SAndroid Build Coastguard Worker // Copyright (C) 2021 The Android Open Source Project 2*6fa2df46SAndroid Build Coastguard Worker // 3*6fa2df46SAndroid Build Coastguard Worker // Licensed under the Apache License, Version 2.0 (the "License"); 4*6fa2df46SAndroid Build Coastguard Worker // you may not use this file except in compliance with the License. 5*6fa2df46SAndroid Build Coastguard Worker // You may obtain a copy of the License at 6*6fa2df46SAndroid Build Coastguard Worker // 7*6fa2df46SAndroid Build Coastguard Worker // http://www.apache.org/licenses/LICENSE-2.0 8*6fa2df46SAndroid Build Coastguard Worker // 9*6fa2df46SAndroid Build Coastguard Worker // Unless required by applicable law or agreed to in writing, software 10*6fa2df46SAndroid Build Coastguard Worker // distributed under the License is distributed on an "AS IS" BASIS, 11*6fa2df46SAndroid Build Coastguard Worker // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12*6fa2df46SAndroid Build Coastguard Worker // See the License for the specific language governing permissions and 13*6fa2df46SAndroid Build Coastguard Worker // limitations under the License. 14*6fa2df46SAndroid Build Coastguard Worker 15*6fa2df46SAndroid Build Coastguard Worker #pragma once 16*6fa2df46SAndroid Build Coastguard Worker 17*6fa2df46SAndroid Build Coastguard Worker #include <pthread.h> 18*6fa2df46SAndroid Build Coastguard Worker 19*6fa2df46SAndroid Build Coastguard Worker #include <ditto/instruction.h> 20*6fa2df46SAndroid Build Coastguard Worker #include <ditto/multithreading_utils.h> 21*6fa2df46SAndroid Build Coastguard Worker 22*6fa2df46SAndroid Build Coastguard Worker namespace dittosuite { 23*6fa2df46SAndroid Build Coastguard Worker 24*6fa2df46SAndroid Build Coastguard Worker class Multithreading : public Instruction { 25*6fa2df46SAndroid Build Coastguard Worker public: 26*6fa2df46SAndroid Build Coastguard Worker inline static const std::string kName = "multithreading"; 27*6fa2df46SAndroid Build Coastguard Worker 28*6fa2df46SAndroid Build Coastguard Worker explicit Multithreading(const Instruction::Params& params, 29*6fa2df46SAndroid Build Coastguard Worker std::vector<std::unique_ptr<Instruction>> instructions, 30*6fa2df46SAndroid Build Coastguard Worker std::vector<MultithreadingParams> thread_params); 31*6fa2df46SAndroid Build Coastguard Worker 32*6fa2df46SAndroid Build Coastguard Worker std::unique_ptr<Result> CollectResults(const std::string& prefix) override; 33*6fa2df46SAndroid Build Coastguard Worker 34*6fa2df46SAndroid Build Coastguard Worker private: 35*6fa2df46SAndroid Build Coastguard Worker void SetUpSingle() override; 36*6fa2df46SAndroid Build Coastguard Worker void RunSingle() override; 37*6fa2df46SAndroid Build Coastguard Worker void TearDownSingle(bool is_last) override; 38*6fa2df46SAndroid Build Coastguard Worker 39*6fa2df46SAndroid Build Coastguard Worker std::vector<std::unique_ptr<Instruction>> instructions_; 40*6fa2df46SAndroid Build Coastguard Worker std::vector<std::thread> threads_; 41*6fa2df46SAndroid Build Coastguard Worker std::vector<MultithreadingParams> thread_params_; 42*6fa2df46SAndroid Build Coastguard Worker pthread_barrier_t barrier_; 43*6fa2df46SAndroid Build Coastguard Worker }; 44*6fa2df46SAndroid Build Coastguard Worker 45*6fa2df46SAndroid Build Coastguard Worker } // namespace dittosuite 46