utility/timer: Use unique_function so our callbacks can be move-only
Change-Id: Ib0b7d9f52b12e48ffacac694dc270a11f476fb0e
Signed-off-by: William A. Kennington III <wak@google.com>
diff --git a/src/sdeventplus/utility/timer.cpp b/src/sdeventplus/utility/timer.cpp
index 242f5d6..638f8e1 100644
--- a/src/sdeventplus/utility/timer.cpp
+++ b/src/sdeventplus/utility/timer.cpp
@@ -44,8 +44,8 @@
std::optional<Duration> interval,
typename source::Time<Id>::Accuracy accuracy) :
expired(false),
- initialized(interval.has_value()), callback(callback), clock(event),
- interval(interval),
+ initialized(interval.has_value()), callback(std::move(callback)),
+ clock(event), interval(interval),
timeSource(event, clock.now() + interval.value_or(Duration::zero()),
accuracy,
std::bind(&Timer::internalCallback, this, std::placeholders::_1,
diff --git a/src/sdeventplus/utility/timer.hpp b/src/sdeventplus/utility/timer.hpp
index 5d36458..bca5566 100644
--- a/src/sdeventplus/utility/timer.hpp
+++ b/src/sdeventplus/utility/timer.hpp
@@ -1,7 +1,7 @@
#pragma once
#include <chrono>
-#include <functional>
+#include <function2/function2.hpp>
#include <optional>
#include <sdeventplus/clock.hpp>
#include <sdeventplus/event.hpp>
@@ -35,7 +35,7 @@
/** @brief Type of the user provided callback function when the
* timer elapses.
*/
- using Callback = std::function<void(Timer<Id>&)>;
+ using Callback = fu2::unique_function<void(Timer<Id>&)>;
Timer(const Timer& other) = delete;
Timer(Timer&& other);