-
Notifications
You must be signed in to change notification settings - Fork 6
Allow for configurable, custom queue type via template parameter #19
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
Merged
Changes from all commits
Commits
Show all changes
4 commits
Select commit
Hold shift + click to select a range
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or 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 hidden or 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 |
|---|---|---|
| @@ -1 +1,2 @@ | ||
| add_subdirectory(everlog) | ||
| add_subdirectory(custom_queue_example) |
This file contains hidden or 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,29 @@ | ||
| if (NOT TARGET farbot) | ||
| include(FetchContent) | ||
|
|
||
| FetchContent_Declare(farbot | ||
| GIT_REPOSITORY https://github.com/hogliux/farbot | ||
| GIT_TAG 0416705394720c12f0d02e55c144e4f69bb06912 | ||
| ) | ||
| # Note we do not "MakeAvailable" here, because farbot does not fully work via FetchContent | ||
| if(NOT farbot_POPULATED) | ||
| FetchContent_Populate(farbot) | ||
| endif() | ||
| add_library(farbot INTERFACE) | ||
| add_library(farbot::farbot ALIAS farbot) | ||
|
|
||
| target_include_directories(farbot INTERFACE | ||
| $<BUILD_INTERFACE:${farbot_SOURCE_DIR}/include> | ||
| $<INSTALL_INTERFACE:include> | ||
| ) | ||
| endif() | ||
|
|
||
| add_executable(custom_queue_example | ||
| customqueuemain.cpp | ||
| ) | ||
|
|
||
| target_link_libraries(custom_queue_example | ||
| PRIVATE | ||
| rtlog::rtlog | ||
| farbot::farbot | ||
| ) |
This file contains hidden or 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,47 @@ | ||
| #include <farbot/fifo.hpp> | ||
| #include <rtlog/rtlog.h> | ||
|
|
||
| template <typename T> class FarbotMPSCQueueWrapper { | ||
| farbot::fifo<T, | ||
| farbot::fifo_options::concurrency::single, // Consumer | ||
| farbot::fifo_options::concurrency::multiple, // Producer | ||
| farbot::fifo_options::full_empty_failure_mode:: | ||
| return_false_on_full_or_empty, // consumer_failure_mode | ||
| farbot::fifo_options::full_empty_failure_mode:: | ||
| overwrite_or_return_default> // producer_failure_mode | ||
|
|
||
| mQueue; | ||
|
|
||
| public: | ||
| using value_type = T; | ||
|
|
||
| FarbotMPSCQueueWrapper(int capacity) : mQueue(capacity) {} | ||
|
|
||
| bool try_enqueue(T &&item) { return mQueue.push(std::move(item)); } | ||
| bool try_dequeue(T &item) { return mQueue.pop(item); } | ||
| }; | ||
|
|
||
| struct LogData {}; | ||
|
|
||
| std::atomic<size_t> gSequenceNumber{0}; | ||
|
|
||
| int main() { | ||
| rtlog::Logger<LogData, 128, 128, gSequenceNumber, FarbotMPSCQueueWrapper> | ||
| logger; | ||
| logger.Log({}, "Hello, World!"); | ||
|
|
||
| logger.PrintAndClearLogQueue( | ||
| [](const LogData &data, size_t sequenceNumber, const char *fstring, ...) { | ||
| (void)data; | ||
| std::array<char, 128> buffer; | ||
|
|
||
| va_list args; | ||
| va_start(args, fstring); | ||
| vsnprintf(buffer.data(), buffer.size(), fstring, args); | ||
| va_end(args); | ||
|
|
||
| printf("{%zu} %s\n", sequenceNumber, buffer.data()); | ||
| }); | ||
|
|
||
| return 0; | ||
| } | ||
This file contains hidden or 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.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@atsushieno I incorporated your work here as an example for future readers. Would you please review this?
I'll make sure you get marked as a co-author in the git commit, as I took much of this verbatim from your branch :)
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Yes everything looks much greater with the customizible queues! I'm glad my changes were of some help.
I don't try hard to push my MPSC stuff in the main code from "example use case", but what I'm concerned however is that people would like to have default implementation for MPSC anyway, and they would simply ask you to incorporate that farbot version (or anything equivalent) after all, just like there is the original SPSC implementation.
For my own purpose I will keep my friendly fork version (maybe not even a fork, just an addon header would work), and I'm a bit concerned that it may be more widely referenced than your original repo as people would usually want to use the logging functionality in multi-threaded apps.
As a library author in this world I understand that I wouldn't like to incorporate external deps that might not match my taste (or being asked to do so), but having third-party fork more popular (especially widely used without my fixes) would not be a great experience.
IF that were the case in the future, I'm always happy to share my stuff and feel free to take them back into this repo.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
That makes sense.
How about this: I submit this change, then either myself or you (if you had time and wanted to) "swap" farbot and readerwriterqueue. Farbot becomes the main dependency, we add two versions of the wrapper - one single producer and one multi-producer. readerwriterqueue becomes the example dependency.
Overall, my only concern with incorporating farbot AND readerwriterqueue together is that we would be downloading more dependencies to user's machines. I already feel partly bad downloading stb, libfmt AND readerwriterqueue. Most libraries I know and trust don't download anything and are "self reliant". I would like to not add additional dependencies to the mix if possible. I agree that it is reasonable for users to want both single producer and multi producer versions of rtlog.
If we swapped in farbot as the primary queue, this would keep the dependency count the same and add more flexibility for the user. It would also be easy for anyone to add a new queue on their own if they wanted it.
What do you think?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
That would be the best solution I agree :-)
I'm working on some other stuff now, but when I have time and if it's not done then I'll take the task (I don't mind overlaps, wouldn't waste too much time anyway).
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Sounds good. I'll ping you in any reviews if I take on the work, please do the same for me!