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.