Skip to content
This repository was archived by the owner on Sep 27, 2019. It is now read-only.

Commit 79389a0

Browse files
committed
Move function definition back because of templates
1 parent 796ca9c commit 79389a0

File tree

2 files changed

+23
-47
lines changed

2 files changed

+23
-47
lines changed

src/common/dedicated_thread_registry.cpp

Lines changed: 0 additions & 43 deletions
This file was deleted.

src/include/common/dedicated_thread_registry.h

Lines changed: 23 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,8 @@
1616
#include <vector>
1717
#include <thread>
1818
#include "common/macros.h"
19-
19+
#include "common/dedicated_thread_task.h"
20+
#include "common/dedicated_thread_owner.h
2021
2122
namespace peloton {
2223
@@ -32,10 +33,24 @@ class DedicatedThreadRegistry {
3233
public:
3334
DedicatedThreadRegistry() = default;
3435
35-
~DedicatedThreadRegistry();
36+
~DedicatedThreadRegistry() {
37+
// Note that if registry is shutting down, it doesn't matter whether
38+
// owners are notified as this class should have the same life cycle
39+
// as the entire peloton process.
40+
41+
for (auto &entry : thread_owners_table_) {
42+
for (auto &task : entry.second) {
43+
task->Terminate();
44+
threads_table_[task.get()].join();
45+
}
46+
}
47+
}
3648
3749
// TODO(tianyu): Remove when we remove singletons
38-
static DedicatedThreadRegistry &GetInstance();
50+
static DedicatedThreadRegistry &GetInstance() {
51+
static DedicatedThreadRegistry registry;
52+
return registry;
53+
}
3954
4055
/**
4156
*
@@ -47,7 +62,11 @@ class DedicatedThreadRegistry {
4762
*/
4863
template <typename Task>
4964
void RegisterDedicatedThread(DedicatedThreadOwner *requester,
50-
std::shared_ptr<Task> task);
65+
std::shared_ptr<Task> task) {
66+
thread_owners_table_[requester].push_back(task);
67+
requester->NotifyNewThread();
68+
threads_table_.emplace(task.get(), std::thread([=] { task->RunTask(); }));
69+
}
5170
5271
// TODO(tianyu): Add code for thread removal
5372

0 commit comments

Comments
 (0)