In PTimedMutex::Wait(const PTimeInterval & waitTime), when pthread_mutex_timedlock is not available or broken (it is broken on our arm platform), the code always sleeps before checking the finish time, which is incorrect.
For example, if you call Wait(0), and fail to acquire the lock, you will sleep for 10 milliseconds before you get back the retrun value.
This is a bigger issue if you use H323EndPoint::FindConnectionWithLock:
PWaitAndSignal mutex(connectionsMutex);
H323Connection * connection; while ((connection = FindConnectionWithoutLocks(token)) != NULL) {
// XXX this will block for 10 milliseconds if the lock can not be acquired! // TryLock calls Wait(0) which sleeps for 10ms on failure switch (connection->TryLock()) {
case 0 : return NULL; case 1 : return connection; } // Could not get connection lock, unlock the endpoint lists so a thread // that has the connection lock gets a chance at the endpoint lists. connectionsMutex.Signal(); PThread::Sleep(20); connectionsMutex.Wait(); }
return NULL;
The code try sleep for 20 milliseconds while the connectionsMutex is unlocked, letting the other thread that hold the connection a chancee to use the endpoint lists, but for each 30 milliseconds cycle, it keeps the endpoint lists locked for 10 milliseconds.
Attached a trivial fix.
Best Regards,
Nir Soffer
I have applied this patch to the PTLib trunk. Thank you very much!
Robert Jongbloed OPAL/OpenH323/PTLib Architect and Co-founder.
-----Original Message----- From: h323plus-bounces@lists.packetizer.com [mailto:h323plus- bounces@lists.packetizer.com] On Behalf Of Nir Soffer Sent: Sunday, 21 September 2008 5:26 AM To: h323plus Subject: [h323plus] PTimedMutex::Wait patch
In PTimedMutex::Wait(const PTimeInterval & waitTime), when pthread_mutex_timedlock is not available or broken (it is broken on our arm platform), the code always sleeps before checking the finish time, which is incorrect.
For example, if you call Wait(0), and fail to acquire the lock, you will sleep for 10 milliseconds before you get back the retrun value.
This is a bigger issue if you use H323EndPoint::FindConnectionWithLock:
PWaitAndSignal mutex(connectionsMutex);
H323Connection * connection; while ((connection = FindConnectionWithoutLocks(token)) != NULL) {
// XXX this will block for 10 milliseconds if the lock can not
be acquired! // TryLock calls Wait(0) which sleeps for 10ms on failure switch (connection->TryLock()) {
case 0 : return NULL; case 1 : return connection; } // Could not get connection lock, unlock the endpoint lists so a
thread // that has the connection lock gets a chance at the endpoint lists. connectionsMutex.Signal(); PThread::Sleep(20); connectionsMutex.Wait(); }
return NULL;
The code try sleep for 20 milliseconds while the connectionsMutex is unlocked, letting the other thread that hold the connection a chancee to use the endpoint lists, but for each 30 milliseconds cycle, it keeps the endpoint lists locked for 10 milliseconds.
Attached a trivial fix.
in gkserver.cxx
variable identifierBase is defined as type time_t and in vs2008 time_t is type __time64_t ( __int64 )
psprintf("%x:%u", identifierBase, nextIdentifier++) always output "xxxxxx:0", then CreateEndPointIdentifier() will return same indentifier at anytime
PString H323GatekeeperServer::CreateEndPointIdentifier() { PWaitAndSignal wait(mutex); //return psprintf("%x:%u", identifierBase, nextIdentifier++); // <---bug here return psprintf("%x:%u", (int)identifierBase, nextIdentifier++); }
Best Regards,
bian
___________________________________________________________ 好玩贺卡等你发,邮箱贺卡全新上线! http://card.mail.cn.yahoo.com/
Hi,
thanks for pointing that out. I applied a slightly different fix to the CVS.
Regards, Jan
Bian wrote:
in gkserver.cxx
variable identifierBase is defined as type time_t and in vs2008 time_t is type __time64_t ( __int64 )
psprintf("%x:%u", identifierBase, nextIdentifier++) always output "xxxxxx:0", then CreateEndPointIdentifier() will return same indentifier at anytime
PString H323GatekeeperServer::CreateEndPointIdentifier() { PWaitAndSignal wait(mutex); //return psprintf("%x:%u", identifierBase, nextIdentifier++); // <---bug here return psprintf("%x:%u", (int)identifierBase, nextIdentifier++); }
Best Regards,
bian
___________________________________________________________
好玩贺卡等你发,邮箱贺卡全新上线! http://card.mail.cn.yahoo.com/
participants (4)
-
Bian
-
Jan Willamowius
-
Nir Soffer
-
Robert Jongbloed