[h323plus] PTimedMutex::Wait patch

Nir Soffer nirs at hyperms.com
Sat Sep 20 15:25:45 EDT 2008


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.

-------------- next part --------------
A non-text attachment was scrubbed...
Name: timedmutex-wait.patch
Type: application/octet-stream
Size: 824 bytes
Desc: not available
URL: <https://lists.packetizer.com/pipermail/h323plus/attachments/20080920/b018acfd/attachment-0003.obj>
-------------- next part --------------



Best Regards,

Nir Soffer




More information about the h323plus mailing list