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

Commit f15681a

Browse files
committed
Address code review comments.
1 parent b6c9e58 commit f15681a

File tree

5 files changed

+52
-36
lines changed

5 files changed

+52
-36
lines changed
Lines changed: 41 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,41 @@
1+
//===----------------------------------------------------------------------===//
2+
//
3+
// Peloton
4+
//
5+
// dedicated_thread_registry.cpp
6+
//
7+
// Identification: src/common/dedicated_thread_registry.cpp
8+
//
9+
// Copyright (c) 2015-2018, Carnegie Mellon University Database Group
10+
//
11+
//===----------------------------------------------------------------------===//
12+
13+
#include "common/dedicated_thread_registry.h"
14+
15+
namespace peloton {
16+
17+
DedicatedThreadRegistry::~DedicatedThreadRegistry() {
18+
// Note that if registry is shutting down, it doesn't matter whether
19+
// owners are notified as this class should have the same life cycle
20+
// as the entire peloton process.
21+
22+
for (auto &entry : thread_owners_table_) {
23+
for (auto &task : entry.second) {
24+
task->Terminate();
25+
threads_table_[task.get()].join();
26+
}
27+
}
28+
}
29+
DedicatedThreadRegistry &DedicatedThreadRegistry::GetInstance() {
30+
static DedicatedThreadRegistry registry;
31+
return registry;
32+
}
33+
34+
template<typename Task>
35+
void DedicatedThreadRegistry::RegisterDedicatedThread(DedicatedThreadOwner *requester,
36+
std::shared_ptr<Task> task) {
37+
thread_owners_table_[requester].push_back(task);
38+
requester->NotifyNewThread();
39+
threads_table_.emplace(task.get(), std::thread([=] { task->RunTask(); }));
40+
}
41+
}

src/include/common/dedicated_thread_registry.h

Lines changed: 8 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -14,11 +14,13 @@
1414
#include <memory>
1515
#include <unordered_map>
1616
#include <vector>
17-
#include "common/dedicated_thread_owner.h"
18-
#include "common/dedicated_thread_task.h"
17+
#include <thread>
1918
#include "common/macros.h"
19+
#include "common/dedicated_thread_task.h"
2020

2121
namespace peloton {
22+
23+
class DedicatedThreadOwner;
2224
/**
2325
* Singleton class responsible for maintaining and dispensing long running
2426
* (dedicated) threads to other system components. The class also serves
@@ -29,24 +31,10 @@ class DedicatedThreadRegistry {
2931
public:
3032
DedicatedThreadRegistry() = default;
3133

32-
~DedicatedThreadRegistry() {
33-
// Note that if registry is shutting down, it doesn't matter whether
34-
// owners are notified as this class should have the same life cycle
35-
// as the entire peloton process.
36-
37-
for (auto &entry : thread_owners_table_) {
38-
for (auto &task : entry.second) {
39-
task->Terminate();
40-
threads_table_[task.get()].join();
41-
}
42-
}
43-
}
34+
~DedicatedThreadRegistry();
4435

4536
// TODO(tianyu): Remove when we remove singletons
46-
static DedicatedThreadRegistry &GetInstance() {
47-
static DedicatedThreadRegistry registry;
48-
return registry;
49-
}
37+
static DedicatedThreadRegistry &GetInstance();
5038

5139
/**
5240
*
@@ -58,11 +46,7 @@ class DedicatedThreadRegistry {
5846
*/
5947
template <typename Task>
6048
void RegisterDedicatedThread(DedicatedThreadOwner *requester,
61-
std::shared_ptr<Task> task) {
62-
thread_owners_table_[requester].push_back(task);
63-
requester->NotifyNewThread();
64-
threads_table_.emplace(task.get(), std::thread([=] { task->RunTask(); }));
65-
}
49+
std::shared_ptr<Task> task);
6650

6751
// TODO(tianyu): Add code for thread removal
6852

@@ -76,4 +60,5 @@ class DedicatedThreadRegistry {
7660
std::vector<std::shared_ptr<DedicatedThreadTask>>>
7761
thread_owners_table_;
7862
};
63+
7964
} // namespace peloton

src/include/threadpool/mono_queue_pool.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -61,6 +61,7 @@ class MonoQueuePool {
6161
return mono_queue_pool;
6262
}
6363

64+
// TODO(Tianyu): Rename to (Brain)QueryHistoryLog or something
6465
static MonoQueuePool &GetBrainInstance() {
6566
uint32_t task_queue_size = settings::SettingsManager::GetInt(
6667
settings::SettingId::brain_task_queue_size);

src/network/connection_handle.cpp

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -107,7 +107,8 @@ DEF_TRANSITION_GRAPH
107107
END_DEF
108108

109109
DEFINE_STATE(GET_RESULT)
110-
ON(WAKEUP) SET_STATE_TO(GET_RESULT) AND_INVOKE(GetResult)
110+
ON(WAKEUP) SET_STATE_TO(GET_RESULT) AND_INVOKE(GetResult)
111+
ON(NEED_DATA) SET_STATE_TO (GET_RESULT) AND_WAIT
111112
ON(PROCEED) SET_STATE_TO(WRITE) AND_INVOKE(ProcessWrite)
112113
END_DEF
113114
END_DEF

src/network/postgres_protocol_handler.cpp

Lines changed: 0 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -1,15 +1,3 @@
1-
//===----------------------------------------------------------------------===//
2-
//
3-
// Peloton
4-
//
5-
// postgres_protocol_handler.cpp
6-
//
7-
// Identification: src/network/postgres_protocol_handler.cpp
8-
//
9-
// Copyright (c) 2015-2017, Carnegie Mellon University Database Group
10-
//
11-
//===----------------------------------------------------------------------===//
12-
131
//===----------------------------------------------------------------------===//
142
//
153
// Peloton

0 commit comments

Comments
 (0)