Skip to content
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

Support moveable objects and allow emplacing #31

Open
wants to merge 7 commits into
base: develop
Choose a base branch
from

Conversation

srjek
Copy link

@srjek srjek commented Feb 28, 2017

This PR extends off of the months old #24 and it's recommended edits. Some additional work was done to make sure it also works with objects that are copy xor move constructible.

@timblechmann
Copy link
Collaborator

in general it looks good to me. i'd merge it, but it would be great if you could add some tests for it.

…-only types

Also:
    * Fix an issue spsc_queue::reset() would not compile for move-only types
    * Fix an issue where having BOOST_NO_CXX11_RVALUE_REFERENCES defined would break compiles
@srjek
Copy link
Author

srjek commented Mar 2, 2017

Tests have been added to spsc_queue_test.cpp to verify the move-only and copy-only structures behave as expected. Also fixed a few issues I came across in the process.

@tnovotny
Copy link

Can this please be go forward. I really need this and want to get rid of my own version (#27).

@@ -405,3 +406,161 @@ BOOST_AUTO_TEST_CASE( spsc_queue_reset_test )

BOOST_REQUIRE(f.empty());
}

Copy link

@tnovotny tnovotny Jul 22, 2017

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Shouldn't there also be a test for a move_only_type like unique_ptr?

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

+1

#ifndef BOOST_NO_CX11_RVALUE_REFERENCES
struct refcount_handle
{
int* p_refcount;

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Not sure about the hungarian notation here. Consider renaming the variable.

@timblechmann
Copy link
Collaborator

@tnovotny thanks for pinging me ... i'll look into it again over the next week

@tnovotny
Copy link

tnovotny commented Jul 22, 2017

@timblechmann it would also be nice if you could also look at my pull request, because if I remember correctly, this will not suffice for move only types, as more of the existing API has to be disabled via enable_if to compile something like spsc_queue<std::unique_ptr<..>>.

I checked. I get a compile errors on
line 111 in bool push(T const & t, T * buffer, size_t max_size).
line 641 in bool push(T const & t).
line 856 in bool push(T const & t).
line 664 in bool consume_one(Functor & f)
...

@tnovotny
Copy link

tnovotny commented Aug 2, 2017

@timblechmann so, here's pinging you again.

@tnovotny
Copy link

@timblechmann i find it really frustrating that you are showing no effort in maintaining this library. would you please give feedback on the outstanding pull requests.

@tnovotny
Copy link

@timblechmann and another two weeks.

@@ -112,6 +114,43 @@ class ringbuffer_base

return true;
}
#ifndef BOOST_NO_CXX11_RVALUE_REFERENCES

bool push(T&& t, T * buffer, size_t max_size)

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

You can make this work on C++98 too with Boost.Move support by using BOOST_RV_REF(T) instead of T&& combined with boost::move instead of std::move.

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

i don't have a strong opinion on this: c++98 compilers are dying out and not so much new code is written for them. we just need to make sure, not to break any existing code by introducing unguarded c++1X constructs

move_and_delete( T * first, T * last, OutputIterator out )
{
if (boost::has_trivial_destructor<T>::value) {
return std::move(first, last, out); // will use memcpy if possible

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Instead of duplicating this function, and using SFINAE to select the desired one, I would just have one implementation. This is safe because while, during overload resolution, the compiler will prefer move assignment, it will still fall back to copy assignment if no move assignment operator is available.

Additionally I'd use boost::move from <boost/move/algorithm.hpp> and boost::move from <boost/move/utility_core.hpp>. That will work without having to use the preprocessor (it's valid regardless of whether BOOST_NO_CXX11_RVALUE_REFERENCES is defined) and additionally supports types that implement move emulation too.

@@ -450,6 +511,23 @@ class compile_time_sized_ringbuffer:
return ringbuffer_base<T>::push(t, data(), max_size);
}

#ifndef BOOST_NO_CXX11_RVALUE_REFERENCES
bool push(T&& t)

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Same as above: BOOST_RV_REF (also on C++98).

This does not apply to the variadic templates below though.

#endif

#endif

/** Pops one object from ringbuffer.
*
* \pre only one thread is allowed to pop data to the spsc_queue

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Just dreaming here, but:

It may be worth considering converting this argument-less pop() from returning bool to boost::optional<T>, which is convertible to bool. Because the current version, just returning bool is kind of worthless for everything except "some event has happened", similar to boost::optional<void> (if we had regular void). That would allow user code like this:

while (auto item = queue.pop())
{
  // process item
}

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

true. one could only introduce a new API queue.pop_optional(). i'd merge a PR if you implement it :)

* \post object will be pushed to the spsc_queue, unless it is full.
* \return true, if the push operation is successful.
*
* \note Thread-safe and wait-free
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

maybe comment about the API which is not available if BOOST_NO_CXX11_RVALUE_REFERENCES is defined

@maierlars
Copy link

Its 2021 now, what is stopping this PR from being merged? There is no emplace for this library, which is an important tool to create exception safe functions. This library is essentially dead?

@timblechmann
Copy link
Collaborator

Its 2021 now, what is stopping this PR from being merged? There is no emplace for this library, which is an important tool to create exception safe functions. This library is essentially dead?

not dead, but unfortunately the author cannot spend much time on it and has no use cases himself for move semantics. furthermore there were two "competing" PRs, which eventually both went stale.

happy to merge any merge-ready PR, though

@tnovotny
Copy link

tnovotny commented Sep 11, 2021

trying to get my PR into boost::lockfree was a very frustrating experience. my PR (#27) was simply closed to go on with this one even though it did not support my use case of move only types such as unique_ptr. my changed PR (#41) received no feedback. so to me, at the time, it felt like this library was stale and eventually I just gave up.

@jwdevel
Copy link

jwdevel commented Nov 11, 2021

happy to merge any merge-ready PR, though

Is #41 merge-ready? It has no conflicts.

Or, if this present PR is preferred, would resolving its merge conflicts make it merge-ready?

I say this just as a random person interested in this feature. I'd be willing to clean up this current PR if that's the desired route.

@tnovotny
Copy link

that was about my experience. poor to no feedback on this topic

@xim
Copy link

xim commented Nov 23, 2021

Just to weigh in, I'd also love to see this functionality merged

@jeremy-murphy
Copy link

Tim, what do you think now that C++98/03 is officially deprecated in Boost? https://pdimov.github.io/articles/phasing_out_cxx03.html

My personal opinion is to stop actively supporting 98/03, so if there are users who need it then it's up to them to actively provide that support in the form of PRs, etc.

And rather than surveying the community to inform a decision (which I did for another library), you'll find out pretty quickly if you just break it and see what happens. :)

@intractabilis
Copy link

Are there any prospects of this being merged?

@timblechmann
Copy link
Collaborator

for 1.86 i'll drop c++03/c++11 support and #90 will be merged

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

10 participants