This repository has been archived by the owner on Sep 18, 2023. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 9
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #59 from Eugene-Mark/master-sync
[PMEM-SHUFFLE-58] Add blocking queue to reduce the effort to persist metadata in ReplicaService.
- Loading branch information
Showing
3 changed files
with
71 additions
and
3 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,27 @@ | ||
#include <mutex> | ||
#include <condition_variable> | ||
#include <deque> | ||
|
||
template <typename T> | ||
class queue | ||
{ | ||
private: | ||
std::mutex d_mutex; | ||
std::condition_variable d_condition; | ||
std::deque<T> d_queue; | ||
public: | ||
void push(T const& value) { | ||
{ | ||
std::unique_lock<std::mutex> lock(this->d_mutex); | ||
d_queue.push_front(value); | ||
} | ||
this->d_condition.notify_one(); | ||
} | ||
T pop() { | ||
std::unique_lock<std::mutex> lock(this->d_mutex); | ||
this->d_condition.wait(lock, [=]{ return !this->d_queue.empty(); }); | ||
T rc(std::move(this->d_queue.back())); | ||
this->d_queue.pop_back(); | ||
return rc; | ||
} | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters