move std function #200

Merged
peri4 merged 4 commits from pitimer_slot into master 2026-03-21 17:00:37 +03:00
2 changed files with 14 additions and 7 deletions
Showing only changes of commit 6efe77a395 - Show all commits

View File

@@ -263,7 +263,7 @@ bool PITimer::start(PISystemTime interval) {
bool PITimer::start(PISystemTime interval, std::function<void()> func) {
if (isRunning()) stopAndWait();
setInterval(interval);
setSlot(func);
setSlot(std::move(func));
return start();
}
@@ -275,7 +275,7 @@ void PITimer::stopAndWait(PISystemTime timeout) {
void PITimer::addDelimiter(int delim, std::function<void(int)> func) {
delims << Delimiter(func, delim);
delims << Delimiter(std::move(func), delim);
}

View File

@@ -126,11 +126,17 @@ public:
//! \~english Sets a tick callback that ignores the delimiter value.
//! \~russian Устанавливает обратный вызов тика, игнорирующий значение делителя.
void setSlot(std::function<void()> func) { ret_func = std::move(func); }
void setSlot(std::function<void()> func) {
ret_func_delim = nullptr;
ret_func = std::move(func);
}
//! \~english Sets a tick callback that receives the current delimiter value.
//! \~russian Устанавливает обратный вызов тика, принимающий текущее значение делителя.
void setSlot(std::function<void(int)> func) { ret_func_delim = std::move(func); }
void setSlot(std::function<void(int)> func) {
ret_func = nullptr;
ret_func_delim = std::move(func);
}
//! \~english Enables locking of the internal mutex around tick processing.
//! \~russian Включает блокировку внутреннего мьютекса вокруг обработки тиков.
@@ -139,7 +145,8 @@ public:
EVENT_HANDLER0(void, unlock) { mutex_.unlock(); }
//! \~english Returns whether the timer drains queued delivery for itself as performer on each main tick. By default \b true.
//! \~russian Возвращает, должен ли таймер обрабатывать отложенную доставку для себя как исполнителя на каждом основном тике. По умолчанию \b true.
//! \~russian Возвращает, должен ли таймер обрабатывать отложенную доставку для себя как исполнителя на каждом основном тике. По
//! умолчанию \b true.
bool isCallQueuedEvents() const { return callEvents; }
//! \~english Enables or disables queued-delivery draining through \a maybeCallQueuedEvents() on each main tick.
@@ -219,7 +226,7 @@ public:
protected:
struct PIP_EXPORT Delimiter {
Delimiter(std::function<void(int)> func_ = nullptr, int delim_ = 1) {
func = func_;
func = std::move(func_);
delim = delim_;
}
std::function<void(int)> func;
@@ -243,7 +250,7 @@ protected:
PIMutex mutex_;
PISystemTime m_interval, m_interval_x5;
PISystemTime m_time_next;
std::function<void()> ret_func = nullptr;
std::function<void()> ret_func = nullptr;
std::function<void(int)> ret_func_delim = nullptr;
PIVector<Delimiter> delims;
PIConditionVariable event;