Skip to content

Commit 03b9be6

Browse files
committed
p1: fix benchmark
Signed-off-by: Alex Chi <[email protected]>
1 parent f29ac61 commit 03b9be6

File tree

3 files changed

+17
-9
lines changed

3 files changed

+17
-9
lines changed

src/include/common/channel.h

Lines changed: 15 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -16,12 +16,11 @@
1616
#include <mutex> // NOLINT
1717
#include <queue>
1818
#include <utility>
19-
#include "readerwriterqueue/readerwriterqueue.h"
2019

2120
namespace bustub {
2221

2322
/**
24-
* Channels allow for safe sharing of data between threads.
23+
* Channels allow for safe sharing of data between threads. This is a multi-producer multi-consumer channel.
2524
*/
2625
template <class T>
2726
class Channel {
@@ -34,18 +33,27 @@ class Channel {
3433
*
3534
* @param element The element to be inserted.
3635
*/
37-
void Put(T element) { q_.enqueue(std::move(element)); }
36+
void Put(T element) {
37+
std::unique_lock<std::mutex> lk(m_);
38+
q_.push(std::move(element));
39+
lk.unlock();
40+
cv_.notify_all();
41+
}
3842

3943
/**
4044
* @brief Gets an element from the shared queue. If the queue is empty, blocks until an element is available.
4145
*/
4246
auto Get() -> T {
43-
T x;
44-
q_.wait_dequeue(x);
45-
return x;
47+
std::unique_lock<std::mutex> lk(m_);
48+
cv_.wait(lk, [&]() { return !q_.empty(); });
49+
T element = std::move(q_.front());
50+
q_.pop();
51+
return element;
4652
}
4753

4854
private:
49-
moodycamel::BlockingReaderWriterQueue<T> q_;
55+
std::mutex m_;
56+
std::condition_variable cv_;
57+
std::queue<T> q_;
5058
};
5159
} // namespace bustub

third_party/readerwriterqueue/readerwriterqueue.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -282,7 +282,7 @@ class MOODYCAMEL_MAYBE_ALIGN_TO_CACHELINE ReaderWriterQueue
282282
// returns false instead. If the queue has at least one element,
283283
// moves front to result using operator=, then returns true.
284284
template<typename U>
285-
bool try_dequeue(U& result) AE_NO_TSAN
285+
bool try_dequeue(U&& result) AE_NO_TSAN
286286
{
287287
#ifndef NDEBUG
288288
ReentrantGuard guard(this->dequeuing);

tools/bpm_bench/bpm_bench.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -191,7 +191,7 @@ auto main(int argc, char **argv) -> int {
191191

192192
uint64_t lru_k_size = 16;
193193
if (program.present("--lru-k-size")) {
194-
bustub_page_cnt = std::stoi(program.get("--lru-k-size"));
194+
lru_k_size = std::stoi(program.get("--lru-k-size"));
195195
}
196196

197197
auto disk_manager = std::make_unique<DiskManagerUnlimitedMemory>();

0 commit comments

Comments
 (0)