From 843994c8fa315109e1fa4da5b9327351663bd167 Mon Sep 17 00:00:00 2001 From: shengxia <496830733@qq.com> Date: Thu, 3 Aug 2023 19:05:12 +0800 Subject: [PATCH] update watchdog struct Signed-off-by: shengxia <496830733@qq.com> --- interfaces/inner_api/ffrt_watchdog.h | 4 ++-- src/dfx/watchdog/watchdog.cpp | 32 +++++++++++----------------- src/queue/queue_monitor.cpp | 4 ++-- 3 files changed, 16 insertions(+), 24 deletions(-) diff --git a/interfaces/inner_api/ffrt_watchdog.h b/interfaces/inner_api/ffrt_watchdog.h index 3947bab..107e392 100644 --- a/interfaces/inner_api/ffrt_watchdog.h +++ b/interfaces/inner_api/ffrt_watchdog.h @@ -19,8 +19,8 @@ typedef void(*ffrt_watchdog_cb)(uint64_t, const char *, uint32_t); FFRT_C_API void ffrt_watchdog_dumpinfo(char *buf, uint32_t len); -FFRT_C_API void ffrt_watchdog_register(ffrt_watchdog_cb *cb, uint32_t timeout_ms, uint32_t interval_ms); -FFRT_C_API ffrt_watchdog_cb *ffrt_watchdog_get_cb(void); +FFRT_C_API void ffrt_watchdog_register(ffrt_watchdog_cb cb, uint32_t timeout_ms, uint32_t interval_ms); +FFRT_C_API ffrt_watchdog_cb ffrt_watchdog_get_cb(void); FFRT_C_API uint32_t ffrt_watchdog_get_timeout(void); FFRT_C_API uint32_t ffrt_watchdog_get_interval(void); #endif /* FFRT_WATCHDOG_H */ \ No newline at end of file diff --git a/src/dfx/watchdog/watchdog.cpp b/src/dfx/watchdog/watchdog.cpp index da0b68a..aeeb7c9 100644 --- a/src/dfx/watchdog/watchdog.cpp +++ b/src/dfx/watchdog/watchdog.cpp @@ -17,27 +17,17 @@ #include "dfx/bbox/bbox.h" namespace ffrt { +constexpr uint32_t DEFAULT_TIMEOUT_MS = 30000; struct WatchdogCfg { -public: - explicit WatchdogCfg(ffrt_watchdog_cb* cb, uint32_t timeout_ms = 30000, - uint32_t interval_ms = 30000) + static inline WatchdogCfg* Instance() { - callback = cb; - timeout = timeout_ms; - interval = interval_ms; - } - ~WatchdogCfg() {} - - uint32_t timeout; - uint32_t interval; - ffrt_watchdog_cb *callback; - - static inline WatchdogCfg* Instance(ffrt_watchdog_cb* cb = nullptr, uint32_t timeout_ms = 30000, - uint32_t interval_ms = 30000) - { - static WatchdogCfg inst(cb, timeout_ms, interval_ms); + static WatchdogCfg inst; return &inst; } + + uint32_t timeout = DEFAULT_TIMEOUT_MS; + uint32_t interval = DEFAULT_TIMEOUT_MS; + ffrt_watchdog_cb callback = nullptr; }; } @@ -60,13 +50,15 @@ void ffrt_watchdog_dumpinfo(char *buf, uint32_t len) } API_ATTRIBUTE((visibility("default"))) -void ffrt_watchdog_register(ffrt_watchdog_cb *cb, uint32_t timeout_ms, uint32_t interval_ms) +void ffrt_watchdog_register(ffrt_watchdog_cb cb, uint32_t timeout_ms, uint32_t interval_ms) { - ffrt::WatchdogCfg::Instance(cb, timeout_ms, interval_ms); + ffrt::WatchdogCfg::Instance()->callback = cb; + ffrt::WatchdogCfg::Instance()->timeout = timeout_ms; + ffrt::WatchdogCfg::Instance()->interval = interval_ms; } API_ATTRIBUTE((visibility("default"))) -ffrt_watchdog_cb *ffrt_watchdog_get_cb(void) +ffrt_watchdog_cb ffrt_watchdog_get_cb(void) { return ffrt::WatchdogCfg::Instance()->callback; } diff --git a/src/queue/queue_monitor.cpp b/src/queue/queue_monitor.cpp index b0a8c2b..7f9ecf5 100644 --- a/src/queue/queue_monitor.cpp +++ b/src/queue/queue_monitor.cpp @@ -137,9 +137,9 @@ void QueueMonitor::CheckQueuesStatus() ", serial task gid=" << taskId << " execution " << timeoutUs_ << "us."; FFRT_LOGE("%s", ss.str().c_str()); - ffrt_watchdog_cb* func = ffrt_watchdog_get_cb(); + ffrt_watchdog_cb func = ffrt_watchdog_get_cb(); if (func) { - (*func)(taskId, ss.str().c_str(), ss.str().size()); + func(taskId, ss.str().c_str(), ss.str().size()); } // reset timeout task timestampe for next warning ResetTaskTimestampAfterWarning(i, taskId);