summaryrefslogtreecommitdiff
path: root/memory_replay/Thread.cpp
diff options
context:
space:
mode:
authorChristopher Ferris <cferris@google.com>2015-09-11 15:34:23 -0700
committerChristopher Ferris <cferris@google.com>2015-09-15 14:33:50 -0700
commit33c03d38298ff359d8829aea91bb02b26caab245 (patch)
tree0fbc1c044f788711b56ad944cb9d73b6b27ec618 /memory_replay/Thread.cpp
parent12f454e24a518d81fe42043b7142582b81694363 (diff)
downloadextras-33c03d38298ff359d8829aea91bb02b26caab245.tar.gz
Tool to replay memory allocation recordings.
Included with the tool are a set of app memory recordings that can be used to judge the abilities of the native memory allocator. Verified the full flow by running valgrind on the host version on all the current dumps and verifying that there are no leak, and no errors. Change-Id: I756224991f04b61ba26c692a30a37aad0c9fb163
Diffstat (limited to 'memory_replay/Thread.cpp')
-rw-r--r--memory_replay/Thread.cpp62
1 files changed, 62 insertions, 0 deletions
diff --git a/memory_replay/Thread.cpp b/memory_replay/Thread.cpp
new file mode 100644
index 00000000..497b288e
--- /dev/null
+++ b/memory_replay/Thread.cpp
@@ -0,0 +1,62 @@
+/*
+ * Copyright (C) 2015 The Android Open Source Project
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+#include <pthread.h>
+
+#include "Action.h"
+#include "Thread.h"
+
+Thread::Thread() {
+ pthread_cond_init(&cond_, nullptr);
+}
+
+Thread::~Thread() {
+ pthread_cond_destroy(&cond_);
+}
+
+void Thread::WaitForReady() {
+ pthread_mutex_lock(&mutex_);
+ while (pending_) {
+ pthread_cond_wait(&cond_, &mutex_);
+ }
+ pthread_mutex_unlock(&mutex_);
+}
+
+void Thread::WaitForPending() {
+ pthread_mutex_lock(&mutex_);
+ while (!pending_) {
+ pthread_cond_wait(&cond_, &mutex_);
+ }
+ pthread_mutex_unlock(&mutex_);
+}
+
+void Thread::SetPending() {
+ pthread_mutex_lock(&mutex_);
+ pending_ = true;
+ pthread_mutex_unlock(&mutex_);
+ pthread_cond_signal(&cond_);
+}
+
+void Thread::ClearPending() {
+ pthread_mutex_lock(&mutex_);
+ pending_ = false;
+ pthread_mutex_unlock(&mutex_);
+ pthread_cond_signal(&cond_);
+}
+
+Action* Thread::CreateAction(uintptr_t key_pointer, const char* type, const char* line) {
+ return Action::CreateAction(key_pointer, type, line, action_memory_);
+}