summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorJens Lorenz <jlorenz@de.adit-jv.com>2018-04-09 16:17:23 +0200
committerJens Lorenz <jlorenz@de.adit-jv.com>2018-04-09 17:04:42 +0200
commit1dc989ac6496b306c33ed77b52855dd62a61f3ca (patch)
treee25b541461522628cf93a16cc77e70da37e3c78f
parentfff370c2d89acfed702b7c615650706c3c1fadd2 (diff)
downloadaudiomanager-1dc989ac6496b306c33ed77b52855dd62a61f3ca.tar.gz
AMUtil: Wakeup of ppoll is now also triggered on addFdPoll
Signed-off-by: Jens Lorenz <jlorenz@de.adit-jv.com>
-rw-r--r--AudioManagerUtilities/include/CAmSocketHandler.h1
-rw-r--r--AudioManagerUtilities/src/CAmSocketHandler.cpp32
2 files changed, 17 insertions, 16 deletions
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
diff --git a/AudioManagerUtilities/src/CAmSocketHandler.cpp b/AudioManagerUtilities/src/CAmSocketHandler.cpp
index e5752b4..90d7a49 100644
--- a/AudioManagerUtilities/src/CAmSocketHandler.cpp
+++ b/AudioManagerUtilities/src/CAmSocketHandler.cpp
@@ -125,7 +125,7 @@ void CAmSocketHandler::start_listenting()
clock_gettime(CLOCK_MONOTONIC, &mStartTime);
#endif
timespec buffertime;
-
+
VectorPollfd_t fdPollingArray; //!<the polling array for ppoll
while (!mDispatchDone)
@@ -234,7 +234,12 @@ void CAmSocketHandler::start_listenting()
*/
void CAmSocketHandler::stop_listening()
{
- mDispatchDone = true;
+ //fire the ending event
+ if (mDispatchDone)
+ return;
+
+ wakeupWorker("stop_listening", END_EVENT);
+
#ifndef WITH_TIMERFD
//this is for all running timers only - we need to handle the additional offset here
if (!mListActiveTimer.empty())
@@ -252,14 +257,15 @@ void CAmSocketHandler::exit_mainloop()
{
//end the while loop
stop_listening();
+}
- //fire the ending filedescriptor
- const uint64_t events = END_EVENT;
- if (write(mEventFd, &events, sizeof(events)) < 0)
+void CAmSocketHandler::wakeupWorker(const std::string & func, const uint64_t value)
+{
+ if (write(mEventFd, &value, sizeof(value)) < 0)
{
- //Failed to write to event fd...
- std::ostringstream msg("CAmSocketHandler::exit_mainloop ");
- msg << "Failed to write to event fd: " << mEventFd << " errno: " << std::strerror(errno);
+ // no log message here, it is already done in main.cpp
+ std::ostringstream msg("CAmSocketHandler::");
+ msg << func << " Failed to write to event fd: " << mEventFd << " errno: " << std::strerror(errno);
throw std::runtime_error(msg.str());
}
}
@@ -442,6 +448,7 @@ am_Error_e CAmSocketHandler::addFDPoll(const int fd,
//add new data to the list
mMapShPoll[fd] = pollData;
+ wakeupWorker("addFDPoll");
handle = pollData.handle;
return (E_OK);
@@ -496,14 +503,7 @@ am_Error_e CAmSocketHandler::removeFDPoll(const sh_pollHandle_t handle, const sh
if (it.second.handle == handle)
{
it.second.state = (rmv == sh_rmv_e::RMV_N_CLS ? poll_states_e::CLOSE : poll_states_e::REMOVE);
-
- static uint64_t events(1);
- if (write(mEventFd, &(++events), sizeof(events)) < 0)
- {
- std::ostringstream msg("CAmSocketHandler::removeFDPoll ");
- msg << "Failed to write to event fd: " << mEventFd << " errno: " << std::strerror(errno);
- throw std::runtime_error(msg.str());
- }
+ wakeupWorker("removeFDPoll");
mSetPollKeys.pollHandles.erase(handle);
return E_OK;
}