-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Rename to group_queue to have a more generic purpose (#23)
- Loading branch information
1 parent
551b9a1
commit 5a30fed
Showing
10 changed files
with
349 additions
and
210 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,51 @@ | ||
#include <algorithm> | ||
#include <chrono> | ||
#include <condition_variable> | ||
#include <cstdio> | ||
#include <iostream> | ||
#include <map> | ||
#include <thread> | ||
|
||
#include "../include/group_queue.h" | ||
|
||
namespace examples::group_queue { | ||
// | ||
// example 1 | ||
// | ||
int Example1() | ||
{ | ||
std::cout << "Group Queue example 1\n"; | ||
|
||
enum class Type | ||
{ | ||
kType1 | ||
}; | ||
enum class GroupType | ||
{ | ||
kGroup1 | ||
}; | ||
|
||
small::group_queue<Type, int, GroupType> q; | ||
q.add_type_group(Type::kType1, GroupType::kGroup1); | ||
|
||
q.push_back(small::EnumPriorities::kNormal, Type::kType1, 1); | ||
|
||
// on some thread | ||
std::pair<Type, int> e{}; | ||
auto ret = q.wait_pop_front(GroupType::kGroup1, &e); | ||
// or wait_pop_front_for( std::chrono::minutes( 1 ), GroupType:kGroup1, &e ); | ||
// ret can be small::EnumLock::kExit, small::EnumLock::kTimeout or ret == small::EnumLock::kElement | ||
if (ret == small::EnumLock::kElement) { | ||
// do something with e | ||
std::cout << "elem from group q has type " << (int)e.first << ", " << e.second << "\n"; | ||
} | ||
|
||
// on main thread no more processing (aborting work) | ||
q.signal_exit_force(); // q.signal_exit_when_done() | ||
|
||
std::cout << "Groups Queue example 1 finish\n\n"; | ||
|
||
return 0; | ||
} | ||
|
||
} // namespace examples::group_queue |
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
Oops, something went wrong.