1*288bf522SAndroid Build Coastguard Worker /* 2*288bf522SAndroid Build Coastguard Worker * Copyright (C) 2015 The Android Open Source Project 3*288bf522SAndroid Build Coastguard Worker * 4*288bf522SAndroid Build Coastguard Worker * Licensed under the Apache License, Version 2.0 (the "License"); 5*288bf522SAndroid Build Coastguard Worker * you may not use this file except in compliance with the License. 6*288bf522SAndroid Build Coastguard Worker * You may obtain a copy of the License at 7*288bf522SAndroid Build Coastguard Worker * 8*288bf522SAndroid Build Coastguard Worker * http://www.apache.org/licenses/LICENSE-2.0 9*288bf522SAndroid Build Coastguard Worker * 10*288bf522SAndroid Build Coastguard Worker * Unless required by applicable law or agreed to in writing, software 11*288bf522SAndroid Build Coastguard Worker * distributed under the License is distributed on an "AS IS" BASIS, 12*288bf522SAndroid Build Coastguard Worker * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13*288bf522SAndroid Build Coastguard Worker * See the License for the specific language governing permissions and 14*288bf522SAndroid Build Coastguard Worker * limitations under the License. 15*288bf522SAndroid Build Coastguard Worker */ 16*288bf522SAndroid Build Coastguard Worker 17*288bf522SAndroid Build Coastguard Worker #pragma once 18*288bf522SAndroid Build Coastguard Worker 19*288bf522SAndroid Build Coastguard Worker #include <stdint.h> 20*288bf522SAndroid Build Coastguard Worker #include <sys/types.h> 21*288bf522SAndroid Build Coastguard Worker 22*288bf522SAndroid Build Coastguard Worker // Forward Declarations. 23*288bf522SAndroid Build Coastguard Worker class Pointers; 24*288bf522SAndroid Build Coastguard Worker class Thread; 25*288bf522SAndroid Build Coastguard Worker 26*288bf522SAndroid Build Coastguard Worker class Threads { 27*288bf522SAndroid Build Coastguard Worker public: 28*288bf522SAndroid Build Coastguard Worker Threads(Pointers* pointers, size_t max_threads); 29*288bf522SAndroid Build Coastguard Worker virtual ~Threads(); 30*288bf522SAndroid Build Coastguard Worker 31*288bf522SAndroid Build Coastguard Worker Thread* CreateThread(pid_t tid); 32*288bf522SAndroid Build Coastguard Worker Thread* FindThread(pid_t tid); 33*288bf522SAndroid Build Coastguard Worker void WaitForAllToQuiesce(); 34*288bf522SAndroid Build Coastguard Worker void Finish(Thread* thread); 35*288bf522SAndroid Build Coastguard Worker void FinishAll(); 36*288bf522SAndroid Build Coastguard Worker num_threads()37*288bf522SAndroid Build Coastguard Worker size_t num_threads() { return num_threads_; } max_threads()38*288bf522SAndroid Build Coastguard Worker size_t max_threads() { return max_threads_; } total_time_nsecs()39*288bf522SAndroid Build Coastguard Worker uint64_t total_time_nsecs() { return total_time_nsecs_; } 40*288bf522SAndroid Build Coastguard Worker 41*288bf522SAndroid Build Coastguard Worker private: 42*288bf522SAndroid Build Coastguard Worker Pointers* pointers_ = nullptr; 43*288bf522SAndroid Build Coastguard Worker Thread* threads_ = nullptr; 44*288bf522SAndroid Build Coastguard Worker size_t data_size_ = 0; 45*288bf522SAndroid Build Coastguard Worker size_t max_threads_ = 0; 46*288bf522SAndroid Build Coastguard Worker size_t num_threads_= 0; 47*288bf522SAndroid Build Coastguard Worker uint64_t total_time_nsecs_ = 0; 48*288bf522SAndroid Build Coastguard Worker 49*288bf522SAndroid Build Coastguard Worker Thread* FindEmptyEntry(pid_t tid); 50*288bf522SAndroid Build Coastguard Worker size_t GetHashEntry(pid_t tid); 51*288bf522SAndroid Build Coastguard Worker 52*288bf522SAndroid Build Coastguard Worker void ClearData(); 53*288bf522SAndroid Build Coastguard Worker 54*288bf522SAndroid Build Coastguard Worker friend Thread; 55*288bf522SAndroid Build Coastguard Worker }; 56