-
Notifications
You must be signed in to change notification settings - Fork 114
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 #81 from andrew-hardin/feature/remove-boost-from-core
Remove boost from core popsift library
- Loading branch information
Showing
9 changed files
with
105 additions
and
49 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 |
---|---|---|
|
@@ -45,3 +45,5 @@ oxford | |
# Temporary files | ||
.DS_Store | ||
|
||
# Downloaded archives for tests. | ||
*.tgz |
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 |
---|---|---|
|
@@ -36,8 +36,10 @@ | |
# | ||
################################################################################ | ||
|
||
|
||
@PACKAGE_INIT@ | ||
|
||
include(CMakeFindDependencyMacro) | ||
find_dependency(Threads REQUIRED) | ||
|
||
include("${CMAKE_CURRENT_LIST_DIR}/@[email protected]") | ||
check_required_components("@PROJECT_NAME@") |
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,56 @@ | ||
#pragma once | ||
|
||
#include <condition_variable> | ||
#include <mutex> | ||
#include <queue> | ||
|
||
namespace popsift { | ||
|
||
/** | ||
* @brief A thread safe wrapper around std::queue (replaces boost::sync_queue). | ||
* @tparam T the value type that's stored in the queue. | ||
*/ | ||
template<typename T> | ||
class SyncQueue { | ||
public: | ||
SyncQueue() = default; | ||
|
||
/** | ||
* @brief Push an item onto the queue and signal it's available. | ||
* @param[in] value the item to add to the queue. | ||
*/ | ||
void push(const T& value) { | ||
std::unique_lock<std::mutex> lock(mtx_); | ||
items_.push(value); | ||
lock.unlock(); | ||
signal_.notify_one(); | ||
} | ||
|
||
/** | ||
* @brief Check if the queue is empty - thread safety via mutex. | ||
* @return True if the queue is empty. | ||
*/ | ||
bool empty() { | ||
std::unique_lock<std::mutex> lock(mtx_); | ||
return items_.empty(); | ||
} | ||
|
||
/** | ||
* @brief Pull an item off the queue, or, wait until one arrives. Blocking. | ||
* @return The front item that was popped off the queue. | ||
*/ | ||
T pull() { | ||
std::unique_lock<std::mutex> lock(mtx_); | ||
signal_.wait(lock, [this] { return !items_.empty(); }); | ||
auto ans = items_.front(); | ||
items_.pop(); | ||
return ans; | ||
} | ||
|
||
private: | ||
std::mutex mtx_; | ||
std::queue<T> items_; | ||
std::condition_variable signal_; | ||
}; | ||
|
||
} // namespace popsift |
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