Skip to content

Commit

Permalink
feat(ThreadSafeQueue): add move semantics
Browse files Browse the repository at this point in the history
  • Loading branch information
Insineer committed Sep 21, 2019
1 parent 8fb0d99 commit 1ed41ad
Showing 1 changed file with 10 additions and 3 deletions.
13 changes: 10 additions & 3 deletions SharedLibrary/Sources/Shared/ThreadSafeQueue.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -11,24 +11,31 @@ namespace uf {
std::queue<T> queue;
std::mutex mutex;
public:
void Push(T t);
void Push(const T &t);
void Push(T &&t);
T Pop();
bool Empty();
uint32_t GetSize();
};

template<class T>
void ThreadSafeQueue<T>::Push(T t) {
void ThreadSafeQueue<T>::Push(const T &t) {
std::scoped_lock lock(mutex);
queue.push(t);
}

template<class T>
void ThreadSafeQueue<T>::Push(T &&t) {
std::scoped_lock lock(mutex);
queue.emplace(std::forward<T>(t));
}

template<class T>
T ThreadSafeQueue<T>::Pop() {
std::scoped_lock lock(mutex);
if (queue.empty())
return nullptr;
T t = queue.front();
T t = std::forward<T>(queue.front());
queue.pop();
return t;
}
Expand Down

0 comments on commit 1ed41ad

Please sign in to comment.