forked from openalpr/openalpr
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Added multi-threaded frame analysis to daemon
- Loading branch information
Showing
6 changed files
with
159 additions
and
87 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
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
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
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,48 @@ | ||
#ifndef SAFE_QUEUE_H_ | ||
#define SAFE_QUEUE_H_ | ||
|
||
#include <queue> | ||
#include <thread> | ||
#include <mutex> | ||
#include <condition_variable> | ||
|
||
template <typename T> | ||
class SafeQueue | ||
{ | ||
public: | ||
T pop() | ||
{ | ||
std::unique_lock<std::mutex> mlock(_mutex); | ||
while (_queue.empty()) { | ||
_cond.wait(mlock); | ||
} | ||
auto val = _queue.front(); | ||
_queue.pop(); | ||
return val; | ||
} | ||
|
||
void push(const T& item) | ||
{ | ||
std::unique_lock<std::mutex> mlock(_mutex); | ||
_queue.push(item); | ||
mlock.unlock(); | ||
_cond.notify_one(); | ||
} | ||
|
||
bool empty() | ||
{ | ||
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; | ||
}; | ||
|
||
#endif |