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