Avoid copy when registering interrupt handler

This commit is contained in:
Martchus 2021-12-31 00:44:52 +01:00
parent 2c9be7c223
commit 4905aa96b4
2 changed files with 3 additions and 3 deletions

View File

@ -78,13 +78,13 @@ bool InterruptHandler::s_handlerRegistered = false;
* (eg. use POSIX write() instead of std::cout).
* \throws Throws std::runtime_error when attempting to create a 2nd instance.
*/
InterruptHandler::InterruptHandler(std::function<void()> handler)
InterruptHandler::InterruptHandler(std::function<void()> &&handler)
{
// set handler function or throw if an instance has already been created
if (s_handler) {
throw runtime_error("Only one instance of InterruptHandler can exist at a time.");
}
s_handler = handler;
s_handler = std::move(handler);
// register handler if not registered yet
if (!s_handlerRegistered) {

View File

@ -165,7 +165,7 @@ inline FieldValue::FieldValue(DenotationType type, unsigned int fileIndex, const
class InterruptHandler {
public:
explicit InterruptHandler(std::function<void()> handler);
explicit InterruptHandler(std::function<void()> &&handler);
~InterruptHandler();
private: