1 /* 2 * Copyright (C) 2015 The Android Open Source Project 3 * 4 * Licensed under the Apache License, Version 2.0 (the "License"); 5 * you may not use this file except in compliance with the License. 6 * You may obtain a copy of the License at 7 * 8 * http://www.apache.org/licenses/LICENSE-2.0 9 * 10 * Unless required by applicable law or agreed to in writing, software 11 * distributed under the License is distributed on an "AS IS" BASIS, 12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 * See the License for the specific language governing permissions and 14 * limitations under the License. 15 */ 16 17 #pragma once 18 19 #include <pthread.h> 20 #include <stdint.h> 21 #include <sys/types.h> 22 23 // Forward Declarations. 24 namespace memory_trace { 25 struct Entry; 26 } 27 class Pointers; 28 29 class Thread { 30 public: 31 Thread(); 32 virtual ~Thread(); 33 34 void WaitForReady(); 35 void WaitForPending(); 36 void SetPending(); 37 void ClearPending(); 38 AddTimeNsecs(uint64_t nsecs)39 void AddTimeNsecs(uint64_t nsecs) { total_time_nsecs_ += nsecs; } 40 set_pointers(Pointers * pointers)41 void set_pointers(Pointers* pointers) { pointers_ = pointers; } pointers()42 Pointers* pointers() { return pointers_; } 43 SetEntry(const memory_trace::Entry * entry)44 void SetEntry(const memory_trace::Entry* entry) { entry_ = entry; } GetEntry()45 const memory_trace::Entry& GetEntry() { return *entry_; } 46 47 private: 48 pthread_mutex_t mutex_ = PTHREAD_MUTEX_INITIALIZER; 49 pthread_cond_t cond_; 50 bool pending_ = false; 51 52 pthread_t thread_id_; 53 pid_t tid_ = 0; 54 uint64_t total_time_nsecs_ = 0; 55 56 Pointers* pointers_ = nullptr; 57 58 const memory_trace::Entry* entry_; 59 60 friend class Threads; 61 }; 62