Contrib separation & ftl::Trampoline#69
Conversation
source/CMakeLists.txt
Outdated
| endif() | ||
|
|
||
| if (FTL_CONTRIB_CHANGES) | ||
| add_definitions(-DFTL_CONTRIB_CHANGES=1) |
There was a problem hiding this comment.
I left this in here accidentally.
|
Frankly, I'm not really a big fan of this interface. The code itself looks perfectly fine for what it does, though I haven't been terribly thorough. My comments in no particular order:
All in all, I think the code is fine, but the interface isn't as friendly as I hoped, and there is a lot of excess machinery that I don't think is needed. |
…achinery; Remove value return support; Remove machinery from AtomicCounter; Tie BoundTrampoline lifetime to Task duration
|
Hey, thanks for the comments! No worries, I knew that this is a controversial proposal ;). Your comments were reasonable, so I went ahead and took most of the changes you found questionable.
I avoided making this change, because I felt it would be too invasive, since it would require all users of the TS to be aware of *Trampoline, but I agree that this would be a better interface. |
|
Overall, it's looking very nice. With the recent changes pulling it back down to C++11, my first question is: do we really need a contrib folder / #ifdef? In my opinion, just put trampoline.h in with all the other files. And get rid of the #ifdef for the tests, and always call them. |
| taskScheduler->AddTask(*ftl::make_trampoline([](int& a, const int& b, const Foo& f, const int d) { a++; }).bind(a, b, f, d), &counter); | ||
| taskScheduler->WaitForCounter(&counter, 0); | ||
| // values are correctly captured and const is respected | ||
| std::cout << a << '\n'; |
There was a problem hiding this comment.
Instead of the cout, can you do a GTEST_ASSERT_*() ?
| target_link_libraries(ftl-test gtest gtest_main ftl) | ||
|
|
||
| GTEST_ADD_TESTS(ftl-test "" ${FIBER_TASKING_LIB_TESTS_SRC}) | ||
| GTEST_ADD_TESTS(ftl-test "" ${FIBER_TASKING_LIB_TESTS_SRC}) No newline at end of file |
cwfitzgerald
left a comment
There was a problem hiding this comment.
Code is looking better. I would agree that we shouldn't have the contrib split as it frankly seems a bit silly.
Code comments/questions:
- Could we call it something other than trampoline. It isn't a very descriptive name.
ftl::BoundFunction,ftl::FunctionCall,ftl::Calleewould all be fine in my book. - What is the purpose of allowing late binding? In every use case I can think of, you construct the trampoline then immediately bind them. Why not just construct the trampoline already pre-bound. It would eliminate most of the problems with forgetting to bind it.
- I'm not a big fan of having to dereference the trampoline in order to use it and by extension the abuse of operator Task to get a task out of it. There's too much type crap going on that isn't easy to reason about. I would prefer there be overloads that accept a trampoline/array of trampoline and that a ready to use trampoline doesn't expose the pointer directly. The thing you handle should be a wrapper around a pointer that disallows you from fucking with the allocation. This wrapper would also allow us to deal with the possible memory leaks from creating a trampoline anywhere other than the call itself.
|
I think trampoline was just chosen because that's what the internal stuff is called in std::thread. If we do end up going with the |
|
Are we still planning on going with that interface? I somehow got the impression that this would be the interface itself. |
|
I think the What are your thoughts? Pros? Cons? |
|
I definitely agree wholeheartedly. I also really don't know what the advantage of something like this is versus just using std::bind/std::function. That's what I used in my implementation and it was something on the order of 20 loc for the whole thing. |
Please find the initial implementation of Trampoline, along with a hypothetical split from the mainline ftl library.
This is not intended to be merged in this form, but I wanted to initiate discussion on this implementation approach.