diff options
Diffstat (limited to 'memory_replay/Threads.cpp')
-rw-r--r-- | memory_replay/Threads.cpp | 21 |
1 files changed, 12 insertions, 9 deletions
diff --git a/memory_replay/Threads.cpp b/memory_replay/Threads.cpp index 61f950ee..81a679e9 100644 --- a/memory_replay/Threads.cpp +++ b/memory_replay/Threads.cpp @@ -26,8 +26,7 @@ #include <new> -#include "Alloc.h" -#include "Pointers.h" +#include "Action.h" #include "Thread.h" #include "Threads.h" @@ -35,11 +34,11 @@ void* ThreadRunner(void* data) { Thread* thread = reinterpret_cast<Thread*>(data); while (true) { thread->WaitForPending(); - const AllocEntry& entry = thread->GetAllocEntry(); - thread->AddTimeNsecs(AllocExecute(entry, thread->pointers())); - bool thread_done = entry.type == THREAD_DONE; + Action* action = thread->GetAction(); + thread->AddTimeNsecs(action->Execute(thread->pointers())); + bool end_thread = action->EndThread(); thread->ClearPending(); - if (thread_done) { + if (end_thread) { break; } } @@ -58,6 +57,11 @@ Threads::Threads(Pointers* pointers, size_t max_threads) data_size_, max_threads_); } + if (Thread::ACTION_SIZE < Action::MaxActionSize()) { + err(1, "Thread action size is too small: ACTION_SIZE %zu, max size %zu\n", + Thread::ACTION_SIZE, Action::MaxActionSize()); + } + threads_ = new (memory) Thread[max_threads_]; } @@ -81,7 +85,7 @@ Thread* Threads::CreateThread(pid_t tid) { thread->tid_ = tid; thread->pointers_ = pointers_; thread->total_time_nsecs_ = 0; - if ((errno = pthread_create(&thread->thread_id_, nullptr, ThreadRunner, thread)) != 0) { + if (pthread_create(&thread->thread_id_, nullptr, ThreadRunner, thread) == -1) { err(1, "Failed to create thread %d: %s\n", tid, strerror(errno)); } @@ -145,10 +149,9 @@ void Threads::Finish(Thread* thread) { } void Threads::FinishAll() { - AllocEntry thread_done = {.type = THREAD_DONE}; for (size_t i = 0; i < max_threads_; i++) { if (threads_[i].tid_ != 0) { - threads_[i].SetAllocEntry(&thread_done); + threads_[i].CreateAction(0, "thread_done", nullptr); threads_[i].SetPending(); Finish(threads_ + i); } |