Skip to content

Commit

Permalink
Changed safequeue implementation to make it compatible with c++98
Browse files Browse the repository at this point in the history
  • Loading branch information
sam-dieck committed Dec 13, 2017
1 parent 33c50e3 commit 2f11e0e
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 16 deletions.
1 change: 0 additions & 1 deletion src/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -130,7 +130,6 @@ ELSE()
ENDIF()


set (CMAKE_CXX_STANDARD 11)
set(CMAKE_CSS_FLAGS_RELEASE "${CMAKE_CXX_FLAGS_RELEASE} -Wall ")
if (NOT IOS)
ADD_EXECUTABLE( alpr main.cpp )
Expand Down
22 changes: 7 additions & 15 deletions src/inc/safequeue.h
Original file line number Diff line number Diff line change
Expand Up @@ -2,30 +2,27 @@
#define SAFE_QUEUE_H_

#include <queue>
#include <thread>
#include <mutex>
#include <condition_variable>
#include "support/tinythread.h"

template <typename T>
class SafeQueue
{
public:
T pop()
{
std::unique_lock<std::mutex> mlock(_mutex);
tthread::lock_guard<tthread::mutex> mlock(_mutex);
while (_queue.empty()) {
_cond.wait(mlock);
_cond.wait(_mutex);
}
auto val = _queue.front();
T val = _queue.front();
_queue.pop();
return val;
}

void push(const T& item)
{
std::unique_lock<std::mutex> mlock(_mutex);
tthread::lock_guard<tthread::mutex> mlock(_mutex);
_queue.push(item);
mlock.unlock();
_cond.notify_one();
}

Expand All @@ -34,15 +31,10 @@ class SafeQueue
return _queue.empty();
}

SafeQueue() = default;
// Disable copying and assignments
SafeQueue(const SafeQueue&) = delete;
SafeQueue& operator=(const SafeQueue&) = delete;

private:
std::queue<T> _queue;
std::mutex _mutex;
std::condition_variable _cond;
tthread::mutex _mutex;
tthread::condition_variable _cond;
};

#endif

0 comments on commit 2f11e0e

Please sign in to comment.