Re: [AD] Mini-synchronization API proposal for 4.1.x

[ Thread Index | Date Index | More lists.liballeg.org/allegro-developers Archives ]


> thread A thread B
> -------- --------
> unlock_mutex
>                 lock_mutex
>                 locked = TRUE
> locked = FALSE

Yes, although this gives only 'false negative' cases, which doesn't really
hurt the purpose of 'locked'.

void al_unlock_mutex(AL_MUTEX *mutex)
{
   ASSERT(system_driver);

   mutex->locked = FALSE;

   if (system_driver->unlock_mutex)
      system_driver->unlock_mutex(mutex->handle);
}

is a little better, although still with 'false negative' cases.

> Also a similar problem in at least `al_destroy_mutex'.  IMHO `locked'
> is unnecessary anyway.

'locked' was only meant to prevent a thread from destroying a mutex while
being its owner. I agree that's pretty weak as a protection, but it defeats
the beginner error of locking the mutex before destroying it in order to be
sure that no other thread is locking it.

--
Eric Botcazou
ebotcazou@xxxxxxxxxx



Mail converted by MHonArc 2.6.19+ http://listengine.tuxfamily.org/