• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
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 struct AllocEntry;
25 class Pointers;
26 
27 class Thread {
28  public:
29   Thread();
30   virtual ~Thread();
31 
32   void WaitForReady();
33   void WaitForPending();
34   void SetPending();
35   void ClearPending();
36 
AddTimeNsecs(uint64_t nsecs)37   void AddTimeNsecs(uint64_t nsecs) { total_time_nsecs_ += nsecs; }
38 
set_pointers(Pointers * pointers)39   void set_pointers(Pointers* pointers) { pointers_ = pointers; }
pointers()40   Pointers* pointers() { return pointers_; }
41 
SetAllocEntry(const AllocEntry * entry)42   void SetAllocEntry(const AllocEntry* entry) { entry_ = entry; }
GetAllocEntry()43   const AllocEntry& GetAllocEntry() { return *entry_; }
44 
45  private:
46   pthread_mutex_t mutex_ = PTHREAD_MUTEX_INITIALIZER;
47   pthread_cond_t cond_;
48   bool pending_ = false;
49 
50   pthread_t thread_id_;
51   pid_t tid_ = 0;
52   uint64_t total_time_nsecs_ = 0;
53 
54   Pointers* pointers_ = nullptr;
55 
56   const AllocEntry* entry_;
57 
58   friend class Threads;
59 };
60