From ea6b62611af630e4bbfb06573d4cae322d71bde7 Mon Sep 17 00:00:00 2001 From: Jens Lorenz Date: Tue, 27 Mar 2018 16:00:38 +0200 Subject: AMUtil: Improve timer implementation and ensure that no fd leak happens Signed-off-by: Jens Lorenz --- AudioManagerUtilities/include/CAmSocketHandler.h | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) (limited to 'AudioManagerUtilities/include/CAmSocketHandler.h') diff --git a/AudioManagerUtilities/include/CAmSocketHandler.h b/AudioManagerUtilities/include/CAmSocketHandler.h index 717f792..0a696a7 100644 --- a/AudioManagerUtilities/include/CAmSocketHandler.h +++ b/AudioManagerUtilities/include/CAmSocketHandler.h @@ -244,7 +244,7 @@ class CAmSocketHandler sh_timer_s() : handle(0) #ifdef WITH_TIMERFD - , fd(0) + , fd(-1) #endif , countdown(), callback(), userData(0) {} @@ -291,7 +291,9 @@ class CAmSocketHandler VectorListPoll_t mListPoll; //! mListTimer; //! mListActiveTimer; //! Date: Wed, 4 Apr 2018 09:43:43 +0200 Subject: AMUtil: Change from mPipe to eventfd This commit is the first commit of a rework of the CAmSochetHandler class. Signed-off-by: Jens Lorenz --- AudioManagerUtilities/include/CAmSocketHandler.h | 8 +++----- 1 file changed, 3 insertions(+), 5 deletions(-) (limited to 'AudioManagerUtilities/include/CAmSocketHandler.h') diff --git a/AudioManagerUtilities/include/CAmSocketHandler.h b/AudioManagerUtilities/include/CAmSocketHandler.h index 0a696a7..5465839 100644 --- a/AudioManagerUtilities/include/CAmSocketHandler.h +++ b/AudioManagerUtilities/include/CAmSocketHandler.h @@ -277,14 +277,12 @@ class CAmSocketHandler typedef enum:uint8_t { - NO_ERROR = 0u, // OK - PIPE_ERROR = 1u, // Pipe error - FD_ERROR = 2u, // Invalid file descriptor - SFD_ERROR = 4u, + NO_ERROR = 0u, // OK + FD_ERROR = 1u, // Invalid file descriptor } internal_codes_e; typedef uint8_t internal_codes_t; - int mPipe[2]; + int mEventFd; bool mDispatchDone; //this starts / stops the mainloop sh_identifier_s mSetPollKeys; //!A set of all used ppoll keys -- cgit v1.2.1 From 29b816429d141584af128256545ca0dc96ce0be3 Mon Sep 17 00:00:00 2001 From: Jens Lorenz Date: Wed, 4 Apr 2018 09:47:25 +0200 Subject: AMUtil: Rework of socketHandler to avoid calls of invalidated objects This patch tries to follow the idea raised in PR26. Following two patches have been reworked: commit: cfe0e77aaf87a0590ceea42f6afa62b0c7d95e80 commit: bc33226f59910a960f62d419ba10d4ea761e3724 The biggest change applies to the internal database. Instead of having a vector for all items which will be copied inside the worker thread the new approach aims a central map which allows to store the sh_poll elements in containers. By this a container is valid until it is remove from map. The remove of items inside a map is now centralized within the worker and only the worker is responsible to keep the ppoll list and the map in sync. This patch also extends the unit tests to stress different timer scenarios. Signed-off-by: Aleksandar Donchev Signed-off-by: Jens Lorenz --- AudioManagerUtilities/include/CAmSocketHandler.h | 33 ++++++++++++------------ 1 file changed, 17 insertions(+), 16 deletions(-) (limited to 'AudioManagerUtilities/include/CAmSocketHandler.h') diff --git a/AudioManagerUtilities/include/CAmSocketHandler.h b/AudioManagerUtilities/include/CAmSocketHandler.h index 5465839..6564d7f 100644 --- a/AudioManagerUtilities/include/CAmSocketHandler.h +++ b/AudioManagerUtilities/include/CAmSocketHandler.h @@ -215,6 +215,14 @@ public: */ class CAmSocketHandler { + typedef enum:uint8_t + { + UNINIT = 0u, // new, uninitialized element which needs to be inserted to ppoll array + VALID = 1u, // it is a valid element in ppoll array + UPDATE = 2u, // update of event information therefore update ppoll array + REMOVE = 3u // remove from ppoll array and internal map + } poll_states_e; + struct sh_poll_s //! checkCB; //check callback std::function dispatchCB; //dispatch callback void* userData; + poll_states_e state; sh_poll_s() : - handle(0), pollfdValue(), prepareCB(), firedCB(), checkCB(), dispatchCB(), userData(0) + handle(0), pollfdValue(), prepareCB(), firedCB(), checkCB(), dispatchCB(), userData(0), state(UNINIT) {} }; @@ -271,8 +280,8 @@ class CAmSocketHandler }; typedef std::reverse_iterator rListTimerIter; //! VectorListPollfd_t; //! VectorListPoll_t; //! VectorPollfd_t; //! MapShPoll_t; //! VectorSignalHandlers_t; //! mListTimer; //! Date: Tue, 27 Mar 2018 14:44:21 +0200 Subject: AMUtil: ONLY timers will be closed in worker thread The removeFDPoll API is extended to allow applications to close the fd by the central worker thread. Signed-off-by: Jens Lorenz --- AudioManagerUtilities/include/CAmSocketHandler.h | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) (limited to 'AudioManagerUtilities/include/CAmSocketHandler.h') diff --git a/AudioManagerUtilities/include/CAmSocketHandler.h b/AudioManagerUtilities/include/CAmSocketHandler.h index 6564d7f..cfa2e89 100644 --- a/AudioManagerUtilities/include/CAmSocketHandler.h +++ b/AudioManagerUtilities/include/CAmSocketHandler.h @@ -50,6 +50,7 @@ namespace am typedef uint16_t sh_pollHandle_t; //! check, std::function dispatch, void* userData, sh_pollHandle_t& handle); am_Error_e addFDPoll(const int fd, const short event, IAmShPollPrepare *prepare, IAmShPollFired *fired, IAmShPollCheck *check, IAmShPollDispatch *dispatch, void* userData, sh_pollHandle_t& handle); - am_Error_e removeFDPoll(const sh_pollHandle_t handle); + am_Error_e removeFDPoll(const sh_pollHandle_t handle, const sh_rmv_e rmv = RMV_ONLY); am_Error_e updateEventFlags(const sh_pollHandle_t handle, const short events); am_Error_e addSignalHandler(std::function callback, sh_pollHandle_t& handle, void * userData); am_Error_e removeSignalHandler(const sh_pollHandle_t handle); -- cgit v1.2.1 From b487c9b8c5e18797e91a77a4a0b447d63a2a42da Mon Sep 17 00:00:00 2001 From: Jens Lorenz Date: Tue, 27 Mar 2018 15:01:03 +0200 Subject: AMUtil: Cleanup indents and whitespaces Signed-off-by: Jens Lorenz --- AudioManagerUtilities/include/CAmSocketHandler.h | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'AudioManagerUtilities/include/CAmSocketHandler.h') diff --git a/AudioManagerUtilities/include/CAmSocketHandler.h b/AudioManagerUtilities/include/CAmSocketHandler.h index cfa2e89..792d190 100644 --- a/AudioManagerUtilities/include/CAmSocketHandler.h +++ b/AudioManagerUtilities/include/CAmSocketHandler.h @@ -449,7 +449,7 @@ private: bool nextHandle(sh_identifier_s & handle); am_Error_e getFDPollData(const sh_pollHandle_t handle, sh_poll_s & outPollData); - + public: CAmSocketHandler(); -- cgit v1.2.1 From 1dc989ac6496b306c33ed77b52855dd62a61f3ca Mon Sep 17 00:00:00 2001 From: Jens Lorenz Date: Mon, 9 Apr 2018 16:17:23 +0200 Subject: AMUtil: Wakeup of ppoll is now also triggered on addFdPoll Signed-off-by: Jens Lorenz --- AudioManagerUtilities/include/CAmSocketHandler.h | 1 + 1 file changed, 1 insertion(+) (limited to 'AudioManagerUtilities/include/CAmSocketHandler.h') diff --git a/AudioManagerUtilities/include/CAmSocketHandler.h b/AudioManagerUtilities/include/CAmSocketHandler.h index 792d190..5ce7f54 100644 --- a/AudioManagerUtilities/include/CAmSocketHandler.h +++ b/AudioManagerUtilities/include/CAmSocketHandler.h @@ -313,6 +313,7 @@ class CAmSocketHandler private: bool fdIsValid(const int fd) const; + void wakeupWorker(const std::string & func, const uint64_t value = 1u); timespec* insertTime(timespec& buffertime); #ifdef WITH_TIMERFD -- cgit v1.2.1 From ab3eea9263623394272017e3f2987d66ab2eb28f Mon Sep 17 00:00:00 2001 From: Jens Lorenz Date: Mon, 9 Apr 2018 16:54:02 +0200 Subject: AMUtil: Store signalfd as file descriptor instead of pollfd handle Signed-off-by: Jens Lorenz --- AudioManagerUtilities/include/CAmSocketHandler.h | 4 +--- 1 file changed, 1 insertion(+), 3 deletions(-) (limited to 'AudioManagerUtilities/include/CAmSocketHandler.h') diff --git a/AudioManagerUtilities/include/CAmSocketHandler.h b/AudioManagerUtilities/include/CAmSocketHandler.h index 5ce7f54..797551d 100644 --- a/AudioManagerUtilities/include/CAmSocketHandler.h +++ b/AudioManagerUtilities/include/CAmSocketHandler.h @@ -294,6 +294,7 @@ class CAmSocketHandler typedef uint8_t internal_codes_t; int mEventFd; + int mSignalFd; bool mDispatchDone; //this starts / stops the mainloop MapShPoll_t mMapShPoll; //! Date: Thu, 7 Jun 2018 18:04:03 +0200 Subject: AMUtil: Fix inconsistent fdPollingArray In case someone removed a fd and closed it opened a new one and added it to the socket handler the container state of the object in map was changed from either REMOVE/CLOSE to UNINIT. This leads to the emplace call in the fdPollingArray vector and the fd is maintained twice. Over the entire runtime there will be zombie fds provided to ppoll functions which will race a POLLERR revent leading to 100% cpu load. Also the CLOSE state is now removed because only the application is aware if a fd has to be closed. For instance calling add/remove in a loop were start_listenting is not running will turn to a system issue were no fds can be provided by the operation system. Signed-off-by: Jens Lorenz --- AudioManagerUtilities/include/CAmSocketHandler.h | 20 ++++++++++---------- 1 file changed, 10 insertions(+), 10 deletions(-) (limited to 'AudioManagerUtilities/include/CAmSocketHandler.h') diff --git a/AudioManagerUtilities/include/CAmSocketHandler.h b/AudioManagerUtilities/include/CAmSocketHandler.h index 797551d..db3207e 100644 --- a/AudioManagerUtilities/include/CAmSocketHandler.h +++ b/AudioManagerUtilities/include/CAmSocketHandler.h @@ -50,7 +50,6 @@ namespace am typedef uint16_t sh_pollHandle_t; //! check, std::function dispatch, void* userData, sh_pollHandle_t& handle); am_Error_e addFDPoll(const int fd, const short event, IAmShPollPrepare *prepare, IAmShPollFired *fired, IAmShPollCheck *check, IAmShPollDispatch *dispatch, void* userData, sh_pollHandle_t& handle); - am_Error_e removeFDPoll(const sh_pollHandle_t handle, const sh_rmv_e rmv = RMV_ONLY); + am_Error_e removeFDPoll(const sh_pollHandle_t handle); am_Error_e updateEventFlags(const sh_pollHandle_t handle, const short events); am_Error_e addSignalHandler(std::function callback, sh_pollHandle_t& handle, void * userData); am_Error_e removeSignalHandler(const sh_pollHandle_t handle); -- cgit v1.2.1