File tree Expand file tree Collapse file tree 3 files changed +17
-9
lines changed
third_party/readerwriterqueue Expand file tree Collapse file tree 3 files changed +17
-9
lines changed Original file line number Diff line number Diff line change 16
16
#include < mutex> // NOLINT
17
17
#include < queue>
18
18
#include < utility>
19
- #include " readerwriterqueue/readerwriterqueue.h"
20
19
21
20
namespace bustub {
22
21
23
22
/* *
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.
25
24
*/
26
25
template <class T >
27
26
class Channel {
@@ -34,18 +33,27 @@ class Channel {
34
33
*
35
34
* @param element The element to be inserted.
36
35
*/
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
+ }
38
42
39
43
/* *
40
44
* @brief Gets an element from the shared queue. If the queue is empty, blocks until an element is available.
41
45
*/
42
46
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;
46
52
}
47
53
48
54
private:
49
- moodycamel::BlockingReaderWriterQueue<T> q_;
55
+ std::mutex m_;
56
+ std::condition_variable cv_;
57
+ std::queue<T> q_;
50
58
};
51
59
} // namespace bustub
Original file line number Diff line number Diff line change @@ -282,7 +282,7 @@ class MOODYCAMEL_MAYBE_ALIGN_TO_CACHELINE ReaderWriterQueue
282
282
// returns false instead. If the queue has at least one element,
283
283
// moves front to result using operator=, then returns true.
284
284
template <typename U>
285
- bool try_dequeue (U& result) AE_NO_TSAN
285
+ bool try_dequeue (U&& result) AE_NO_TSAN
286
286
{
287
287
#ifndef NDEBUG
288
288
ReentrantGuard guard (this ->dequeuing );
Original file line number Diff line number Diff line change @@ -191,7 +191,7 @@ auto main(int argc, char **argv) -> int {
191
191
192
192
uint64_t lru_k_size = 16 ;
193
193
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" ));
195
195
}
196
196
197
197
auto disk_manager = std::make_unique<DiskManagerUnlimitedMemory>();
You can’t perform that action at this time.
0 commit comments