On Wed, 2010-01-06 at 13:37 -0500, Dale Worley wrote:
> As you all know, an extremely convenient way to seize a semaphore is to
> use an OsLock object:
> 
>    ...
>    {
>       OsLock lock(semaphore);
> 
>       ...do stuff, protected by 'semaphore'...
>    }
>    ...
> 
> But sometimes this paradigm is awkward because at the end of "do stuff",
> you want to call another function, and you need to release 'semaphore'
> before you call that function.  Of course, you can have the protected
> code set a flag variable, and then do the call outside of the block with
> the OsLock, but that is hard to read, and the coding gets awkward.  (It
> gets even messier when the arguments to the function "should" be
> temporary variables declared in nested blocks.)
> 
> I've coded an addition to OsLock that allows the code to "prematurely"
> release the lock, before the OsLock object is destroyed.  The paradigm
> is:
> 
>    ...
>    {
>       OsLock lock(semaphore);
> 
>       ...do stuff, protected by 'semaphore'...
>       lock.release();
>       // 'semaphore' is free now.
>       external_method();
>    }
>    ...
> 
> Of course, you have to check that flow of control from the call
> of ::release() to the end of the block declaring the OsLock does not
> require 'semaphore' be held.
> 
> The current code for this change is available as:  
> svn diff -c 17614 
> http://sipxecs.sipfoundry.org/rep/sipXecs/branches/user_dworley_subscribe/sipXportLib
> 
> Comments?

Why not just use the underlying OsBSem in the first place?  It's exactly
what you just did - the only advantage of OsLock is that it releases
based on the scope.


_______________________________________________
sipx-dev mailing list [email protected]
List Archive: http://list.sipfoundry.org/archive/sipx-dev
Unsubscribe: http://list.sipfoundry.org/mailman/listinfo/sipx-dev
sipXecs IP PBX -- http://www.sipfoundry.org/

Reply via email to