OSDN Git Service

am 241ffafa: Prepare for BoringSSL update.
[android-x86/system-extras.git] / memory_replay / Thread.h
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 #ifndef _MEMORY_REPLAY_THREAD_H
18 #define _MEMORY_REPLAY_THREAD_H
19
20 #include <pthread.h>
21 #include <stdint.h>
22 #include <sys/types.h>
23
24 class Action;
25 class Pointers;
26
27 constexpr size_t ACTION_MEMORY_SIZE = 128;
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
39   Action* CreateAction(uintptr_t key_pointer, const char* type, const char* line);
40
41   void set_pointers(Pointers* pointers) { pointers_ = pointers; }
42   Pointers* pointers() { return pointers_; }
43
44   Action* GetAction() { return reinterpret_cast<Action*>(action_memory_); }
45
46  private:
47   pthread_mutex_t mutex_ = PTHREAD_MUTEX_INITIALIZER;
48   pthread_cond_t cond_;
49   bool pending_ = false;
50
51   pthread_t thread_id_;
52   pid_t tid_ = 0;
53
54   Pointers* pointers_ = nullptr;
55
56   // Per thread memory for an Action. Only one action can be processed.
57   // at a time.
58   static constexpr size_t ACTION_SIZE = 128;
59   uint8_t action_memory_[ACTION_SIZE];
60
61   friend class Threads;
62 };
63
64 #endif // _MEMORY_REPLAY_THREAD_H