Apply Wait and signal awake is my suggestion.
Before wait, it need to check the receive queue and awake from wait when
received message happen.
But there three point to consider.
1. From OCProcess some internal call exists which requires timeout check. This
mean OCProcess should be called after each timeout happens.
This may requires timeout management logic as like IoTivty-Lite with returning
remaining timeout period from OCProcess().
2.There are two points calling OCProcess() periodically which is
InProcServerWrapper::processFunc() and InProcClientWrapper::listeningFunc().
Two entities will receive the signal and race to execute the OCProcess() and
they are locked with recursive mutex. This may need another structure change.
3. OCProcess() and other OC API call are synchronized with recursive mutex. I
don’t know detail if this may requires additional consideration.
ts = OCProcess();
pthread_mutex_lock(&mutex);
if (is_queue_empty()) {
if (ts) {
pthread_cond_wait(&cv, &mutex);
} else {
pthread_cond_timedwait(&cv, &mutex, &ts);
}
}
BR, Uze Choi
From: [email protected] [mailto:[email protected]]
On Behalf Of Ravee
Sent: Friday, November 23, 2018 11:04 PM
To: [email protected]
Subject: Re: [dev] Thread wake up every 10ms
Any suggestions, or patches to try async mechanism instead of polling?
On Fri, Nov 23, 2018 at 5:37 PM Raveendranath Kondrakunta
<[email protected]> wrote:
Hi,
I found a function where the thread wakes up every 10ms, On IoT devices, we
except to save power, however this function is waking up every 10ms and
defeating the purpose. We need to relook at the design here.
void InProcServerWrapper::processFunc()
{
auto cLock = m_csdkLock.lock();
while(cLock && m_threadRun)
{
OCStackResult result;
{
std::lock_guard<std::recursive_mutex> lock(*cLock);
result = OCProcess();
}
if(OC_STACK_ERROR == result)
{
oclog() << "OCProcess failed with result " << result
<<std::flush;
// ...the value of variable result is simply ignored for now.
}
std::this_thread::sleep_for(std::chrono::milliseconds(10));
}
}
-Ravee
-=-=-=-=-=-=-=-=-=-=-=-
Links: You receive all messages sent to this group.
View/Reply Online (#10026):
https://lists.iotivity.org/g/iotivity-dev/message/10026
Mute This Topic: https://lists.iotivity.org/mt/28292450/21656
Group Owner: [email protected]
Unsubscribe: https://lists.iotivity.org/g/iotivity-dev/unsub
[[email protected]]
-=-=-=-=-=-=-=-=-=-=-=-