microsoft / arcana.cpp

Arcana.cpp is a collection of helpers and utility code for low overhead, cross platform C++ implementation of task-based asynchrony.
MIT License
78 stars 24 forks source link

Uncopyable work queue #34

Open syntheticmagus opened 2 years ago

syntheticmagus commented 2 years ago

Modified dispatcher.h to use uncopyable inplace_functions. This required some significant modification to the uncopyable features added to inplace_function previously, as that implementation had some serious flaws. In particular, while the implementation prevented copying and prevented the copy constructor from existing, it didn't actually delete the copy constructor. This meant that code which was simply looking to see whether uncopyable inplace_functions had a copy constructor -- notably std::is_copy_constructible -- to see that the copy constructor still existed and to conclude, therefore, that the type was copyable. This caused problems when it led MSVC's implementation of certain STL containers to elect to copy rather than move, only to fail when the copy constructor turned out to be unusable.

To solve this problem, the copy constructor needed to be deleted, not merely unusable; and to do that, the uncopyable version of the inplace_function needed to be a specialization of the entire type, not just of specific functions. Thus, inplace_function.h now contains two inplace_function specializations, one copyable and one not, with the shared behavior factored out as much as possible into a separate impl. With this change, std::is_copy_constructible is able to correctly determine the copyability of inplace_functions, leading MSVC's STL to make the right decisions and allowing us to use uncopyable inplace_functions in dispatcher.h.