Avoid copy when registering interrupt handler
This commit is contained in:
parent
2c9be7c223
commit
4905aa96b4
|
@ -78,13 +78,13 @@ bool InterruptHandler::s_handlerRegistered = false;
|
||||||
* (eg. use POSIX write() instead of std::cout).
|
* (eg. use POSIX write() instead of std::cout).
|
||||||
* \throws Throws std::runtime_error when attempting to create a 2nd instance.
|
* \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
|
// set handler function or throw if an instance has already been created
|
||||||
if (s_handler) {
|
if (s_handler) {
|
||||||
throw runtime_error("Only one instance of InterruptHandler can exist at a time.");
|
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
|
// register handler if not registered yet
|
||||||
if (!s_handlerRegistered) {
|
if (!s_handlerRegistered) {
|
||||||
|
|
|
@ -165,7 +165,7 @@ inline FieldValue::FieldValue(DenotationType type, unsigned int fileIndex, const
|
||||||
|
|
||||||
class InterruptHandler {
|
class InterruptHandler {
|
||||||
public:
|
public:
|
||||||
explicit InterruptHandler(std::function<void()> handler);
|
explicit InterruptHandler(std::function<void()> &&handler);
|
||||||
~InterruptHandler();
|
~InterruptHandler();
|
||||||
|
|
||||||
private:
|
private:
|
||||||
|
|
Loading…
Reference in New Issue