From: Seonah Moon Date: Thu, 20 May 2021 07:03:53 +0000 (+0900) Subject: tool: Use a different timerfd per each dp X-Git-Tag: submit/tizen/20210531.043146~4 X-Git-Url: http://review.tizen.org/git/?a=commitdiff_plain;h=1e9bdc0c3e3d2b94e2a3d6cde5df36011c114d5a;p=platform%2Fcore%2Fapi%2Fvine.git tool: Use a different timerfd per each dp Change-Id: Ic0d922609c98bd430f557b525198b609f0b0ccfa --- diff --git a/tool/tool_run.cpp b/tool/tool_run.cpp index ab7632b..83c25a5 100644 --- a/tool/tool_run.cpp +++ b/tool/tool_run.cpp @@ -12,6 +12,7 @@ #include #include #include +#include #define RESET_COLOR "\e[m" #define MAKE_RED "\e[31m" @@ -23,7 +24,6 @@ extern int interrupt_flag; static int epollfd = 0; -static int timerfd = 0; static FILE *log_file = NULL; static struct { @@ -60,8 +60,9 @@ static struct { .is_sec = false, }; +static std::map timerfds; static int send_message(vine_dp_h dp); -static void _stop_message_timer(); +static void _stop_message_timer(vine_dp_h dp); static void __print_received_data(unsigned char *buf, size_t len) { @@ -86,7 +87,7 @@ static void __received_cb(vine_dp_h dp, size_t received_len, void *user_data) static void __terminated_cb(vine_dp_h dp, void *user_data) { printf("peer is terminated.\n"); - _stop_message_timer(); + _stop_message_timer(dp); } static void __opened_cb(vine_dp_h dp, vine_error_e result, void *user_data) @@ -221,7 +222,7 @@ static void _start_message_timer(vine_dp_h dp, int sec) if (sec <= 0) return; - timerfd = timerfd_create(CLOCK_MONOTONIC, 0); + int timerfd = timerfd_create(CLOCK_MONOTONIC, 0); if (timerfd == -1) return; @@ -235,26 +236,44 @@ static void _start_message_timer(vine_dp_h dp, int sec) return; } + timerfds.insert(std::make_pair(dp, timerfd)); struct epoll_event ev; ev.events = EPOLLIN; ev.data.ptr = (void *)dp; epoll_ctl(epollfd, EPOLL_CTL_ADD, timerfd, &ev); } -static void _stop_message_timer() +static void _stop_message_timer(vine_dp_h dp) { - if (timerfd <= 0) + auto it = timerfds.find(dp); + if (it == timerfds.end()) return; + int timerfd = it->second; + if (timerfd <= 0) { + timerfds.erase(it); + return; + } + epoll_ctl(epollfd, EPOLL_CTL_DEL, timerfd, NULL); close(timerfd); - timerfd = 0; + timerfds.erase(it); +} + +static void _stop_message_timer_all() +{ + for (auto &it : timerfds) { + if (it.second <= 0) + continue; + close(it.second); + } + timerfds.clear(); } static void _message_timer_handler(void *user_data) { - vine_dp_h dp = (vine_dp_h)user_data; - _stop_message_timer(); + vine_dp_h dp = (vine_dp_h) user_data; + _stop_message_timer(dp); send_message(dp); } @@ -307,7 +326,6 @@ static int _send_message(vine_dp_h dp) int ret = vine_dp_send(dp, buf, len); printf("%s to send a message.\n", ret == VINE_ERROR_NONE ? "Succeeded" : "Failed"); - _start_message_timer(dp, vine_configs.interval); return ret; } @@ -340,8 +358,7 @@ static void deinit() { tool_config_deinit(); - if (timerfd) - _stop_message_timer(); + _stop_message_timer_all(); if (log_file) { fclose(log_file);