-
Notifications
You must be signed in to change notification settings - Fork 30
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
imagelist: Use thread-safe queue for thumbnail queue
Moved thread-safe queue into it's own header so it can be used in both the imagelist and imagefetcher.
- Loading branch information
Showing
4 changed files
with
51 additions
and
55 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,40 @@ | ||
#ifndef _TSQUEUE_H_ | ||
#define _TSQUEUE_H_ | ||
|
||
#include <mutex> | ||
#include <queue> | ||
|
||
namespace AhoViewer | ||
{ | ||
template <typename T> | ||
class TSQueue | ||
{ | ||
public: | ||
bool push(T v) | ||
{ | ||
std::unique_lock<std::mutex> lock(m_Mutex); | ||
m_Queue.push(v); | ||
return true; | ||
} | ||
bool pop(T &v) | ||
{ | ||
std::unique_lock<std::mutex> lock(m_Mutex); | ||
if (m_Queue.empty()) | ||
return false; | ||
v = m_Queue.front(); | ||
m_Queue.pop(); | ||
return true; | ||
} | ||
void clear() | ||
{ | ||
std::unique_lock<std::mutex> lock(m_Mutex); | ||
while (!m_Queue.empty()) m_Queue.pop(); | ||
} | ||
|
||
private: | ||
std::queue<T> m_Queue; | ||
std::mutex m_Mutex; | ||
}; | ||
} | ||
|
||
#endif /* _TSQUEUE_H_ */ |