Re: [AD] XInitThreads

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


On Sunday 21 May 2006 07:27, Milan Mimica wrote:
> Are recursive calls to XLOCK/XUNLOCK valid?

Yes, Allegro's mutex's are recursive. At least in the Unix side of things:

void _unix_lock_mutex(void *handle)
{
   struct my_mutex *mx = (struct my_mutex *)handle;

   if (mx->owner != pthread_self()) {
      pthread_mutex_lock(&mx->actual_mutex);
      mx->owner = pthread_self();
   }

   mx->lock_count++;
}

Though I see a bug with that. Can pthread_self() ever return (pthread_t)0? My 
man pages say pthread_self just returns the thread identifier. If a thread 
has an identifier of 0, it would never attempt a lock. It'd need to be 
changed to:

   if (mx->lock_count == 0 || mx->owner != pthread_self()) {


Though still, I'd recommend moving to X's display lock functions for 
XLOCK/XUNLOCK. That's what it's supposed to be, after all. I don't see the 
point in an option, either. An option for improper behavior?




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