xref: /aosp_15_r20/system/extras/memory_replay/Thread.h (revision 288bf5226967eb3dac5cce6c939ccc2a7f2b4fe5)
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 <pthread.h>
20*288bf522SAndroid Build Coastguard Worker #include <stdint.h>
21*288bf522SAndroid Build Coastguard Worker #include <sys/types.h>
22*288bf522SAndroid Build Coastguard Worker 
23*288bf522SAndroid Build Coastguard Worker // Forward Declarations.
24*288bf522SAndroid Build Coastguard Worker namespace memory_trace {
25*288bf522SAndroid Build Coastguard Worker struct Entry;
26*288bf522SAndroid Build Coastguard Worker }
27*288bf522SAndroid Build Coastguard Worker class Pointers;
28*288bf522SAndroid Build Coastguard Worker 
29*288bf522SAndroid Build Coastguard Worker class Thread {
30*288bf522SAndroid Build Coastguard Worker  public:
31*288bf522SAndroid Build Coastguard Worker   Thread();
32*288bf522SAndroid Build Coastguard Worker   virtual ~Thread();
33*288bf522SAndroid Build Coastguard Worker 
34*288bf522SAndroid Build Coastguard Worker   void WaitForReady();
35*288bf522SAndroid Build Coastguard Worker   void WaitForPending();
36*288bf522SAndroid Build Coastguard Worker   void SetPending();
37*288bf522SAndroid Build Coastguard Worker   void ClearPending();
38*288bf522SAndroid Build Coastguard Worker 
AddTimeNsecs(uint64_t nsecs)39*288bf522SAndroid Build Coastguard Worker   void AddTimeNsecs(uint64_t nsecs) { total_time_nsecs_ += nsecs; }
40*288bf522SAndroid Build Coastguard Worker 
set_pointers(Pointers * pointers)41*288bf522SAndroid Build Coastguard Worker   void set_pointers(Pointers* pointers) { pointers_ = pointers; }
pointers()42*288bf522SAndroid Build Coastguard Worker   Pointers* pointers() { return pointers_; }
43*288bf522SAndroid Build Coastguard Worker 
SetEntry(const memory_trace::Entry * entry)44*288bf522SAndroid Build Coastguard Worker   void SetEntry(const memory_trace::Entry* entry) { entry_ = entry; }
GetEntry()45*288bf522SAndroid Build Coastguard Worker   const memory_trace::Entry& GetEntry() { return *entry_; }
46*288bf522SAndroid Build Coastguard Worker 
47*288bf522SAndroid Build Coastguard Worker  private:
48*288bf522SAndroid Build Coastguard Worker   pthread_mutex_t mutex_ = PTHREAD_MUTEX_INITIALIZER;
49*288bf522SAndroid Build Coastguard Worker   pthread_cond_t cond_;
50*288bf522SAndroid Build Coastguard Worker   bool pending_ = false;
51*288bf522SAndroid Build Coastguard Worker 
52*288bf522SAndroid Build Coastguard Worker   pthread_t thread_id_;
53*288bf522SAndroid Build Coastguard Worker   pid_t tid_ = 0;
54*288bf522SAndroid Build Coastguard Worker   uint64_t total_time_nsecs_ = 0;
55*288bf522SAndroid Build Coastguard Worker 
56*288bf522SAndroid Build Coastguard Worker   Pointers* pointers_ = nullptr;
57*288bf522SAndroid Build Coastguard Worker 
58*288bf522SAndroid Build Coastguard Worker   const memory_trace::Entry* entry_;
59*288bf522SAndroid Build Coastguard Worker 
60*288bf522SAndroid Build Coastguard Worker   friend class Threads;
61*288bf522SAndroid Build Coastguard Worker };
62