summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorBodam Nam <bodamnam@google.com>2023-03-15 06:14:24 +0000
committerAndroid (Google) Code Review <android-gerrit@google.com>2023-03-15 06:14:24 +0000
commit09959ed2a29904809db98ed576b4c09061617d25 (patch)
tree6f4ce17abeb81fb234d07fde0d94b05656902bce
parent196d33d6e4691886bf15ed9adbb034c7bc87646f (diff)
parent3f2f6fcc77418e09f43b9b9804cc4bd304f3ffdd (diff)
downloadImsMedia-09959ed2a29904809db98ed576b4c09061617d25.tar.gz
Merge "Fix the StreamScheduler thread running infinite loop" into udc-dev
-rw-r--r--service/src/com/android/telephony/imsmedia/lib/libimsmedia/core/StreamScheduler.cpp70
-rw-r--r--service/src/com/android/telephony/imsmedia/lib/libimsmedia/core/include/StreamScheduler.h1
2 files changed, 28 insertions, 43 deletions
diff --git a/service/src/com/android/telephony/imsmedia/lib/libimsmedia/core/StreamScheduler.cpp b/service/src/com/android/telephony/imsmedia/lib/libimsmedia/core/StreamScheduler.cpp
index e3a59796..9184212c 100644
--- a/service/src/com/android/telephony/imsmedia/lib/libimsmedia/core/StreamScheduler.cpp
+++ b/service/src/com/android/telephony/imsmedia/lib/libimsmedia/core/StreamScheduler.cpp
@@ -19,11 +19,12 @@
#include <stdint.h>
#include <chrono>
#include <thread>
+#include <algorithm>
using namespace std::chrono;
-#define RUN_WAIT_TIMEOUT 6
-#define STOP_WAIT_TIMEOUT 1000
+#define RUN_WAIT_TIMEOUT_MS 1
+#define STOP_WAIT_TIMEOUT_MS 1000
StreamScheduler::StreamScheduler() {}
@@ -85,7 +86,7 @@ void StreamScheduler::Stop()
{
StopThread();
Awake();
- mConditionExit.wait_timeout(STOP_WAIT_TIMEOUT);
+ mConditionExit.wait_timeout(STOP_WAIT_TIMEOUT_MS);
}
IMLOGD1("[Stop] [%p] exit", this);
@@ -96,63 +97,48 @@ void StreamScheduler::Awake()
mConditionMain.signal();
}
-BaseNode* StreamScheduler::DetermineProcessingNode()
+void StreamScheduler::RunRegisteredNode()
{
- if (IsThreadStopped())
- {
- return nullptr;
- }
-
- BaseNode* pRetNode = nullptr;
- uint32_t nMaxDataInNode = 0;
+ // the list to contain non-source type node
+ std::list<BaseNode*> listNodesToRun;
for (auto& node : mlistRegisteredNode)
{
- if (node != nullptr && !node->IsRunTime() && !node->IsSourceNode())
+ if (node != nullptr && node->GetState() == kNodeStateRunning && !node->IsRunTime())
{
- uint32_t nDataInNode = node->GetDataCount();
-
- if (nDataInNode > 0 && nDataInNode >= nMaxDataInNode)
+ if (node->IsSourceNode()) // process the source node
{
- pRetNode = node;
- nMaxDataInNode = nDataInNode;
+ node->ProcessData();
+ }
+ else if (node->GetDataCount() > 0)
+ {
+ listNodesToRun.push_back(node); // store node to run
}
}
}
- return pRetNode;
-}
-
-void StreamScheduler::RunRegisteredNode()
-{
- // run source nodes
- for (auto& node : mlistRegisteredNode)
- {
- if (node != nullptr && node->GetState() == kNodeStateRunning && !node->IsRunTime() &&
- node->IsSourceNode())
- {
- node->ProcessData();
- }
- }
-
- for (;;)
+ while (!listNodesToRun.empty())
{
- BaseNode* pNode = DetermineProcessingNode();
-
- if (pNode == nullptr)
+ std::list<BaseNode*>::iterator maxNode =
+ std::max_element(listNodesToRun.begin(), listNodesToRun.end(),
+ [=](BaseNode* a, BaseNode* b)
+ {
+ return a->GetDataCount() < b->GetDataCount();
+ });
+
+ if (maxNode == listNodesToRun.end())
{
break;
}
- if (pNode->GetState() == kNodeStateRunning)
- {
- pNode->ProcessData();
- }
+ (*maxNode)->ProcessData(); // process the non runtime node
if (IsThreadStopped())
{
break;
}
+
+ listNodesToRun.remove(*maxNode);
};
}
@@ -188,10 +174,10 @@ void* StreamScheduler::run()
break;
}
- mConditionMain.wait_timeout(RUN_WAIT_TIMEOUT / 2);
+ mConditionMain.wait_timeout(RUN_WAIT_TIMEOUT_MS);
}
mConditionExit.signal();
IMLOGD1("[run] [%p] exit", this);
return nullptr;
-}
+} \ No newline at end of file
diff --git a/service/src/com/android/telephony/imsmedia/lib/libimsmedia/core/include/StreamScheduler.h b/service/src/com/android/telephony/imsmedia/lib/libimsmedia/core/include/StreamScheduler.h
index b083096a..f9612c5d 100644
--- a/service/src/com/android/telephony/imsmedia/lib/libimsmedia/core/include/StreamScheduler.h
+++ b/service/src/com/android/telephony/imsmedia/lib/libimsmedia/core/include/StreamScheduler.h
@@ -37,7 +37,6 @@ public:
virtual void* run();
private:
- BaseNode* DetermineProcessingNode();
void RunRegisteredNode();
std::list<BaseNode*> mlistRegisteredNode;
ImsMediaCondition mConditionMain;