Branch: Tag:

1997-09-01

1997-09-01 14:14:30 by Per Hedbor <ph@opera.com>

Made mutexes reentrant.
I know this is a somewhat controversial feature, but it simplifies
threaded programming quite a lot...

Rev: src/threads.c:1.27

1:   #include "global.h" - RCSID("$Id: threads.c,v 1.26 1997/09/01 00:59:33 per Exp $"); + RCSID("$Id: threads.c,v 1.27 1997/09/01 14:14:30 per Exp $");      int num_threads = 1;   int threads_disabled = 0;
181:       pop_n_elems(args);    m=THIS_MUTEX; -  +  o=clone_object(mutex_key,0); +  mt_lock(& mutex_kluge);    if(m->key && OB2KEY(m->key)->owner == thread_id)    { -  push_int(0); +  m->key->refs++; +  push_object(m->key); +  mt_unlock(&mutex_kluge);    return; -  +  +  mt_unlock(&mutex_kluge);    error("Recursive mutex locks!\n");    }    -  o=clone_object(mutex_key,0); -  mt_lock(& mutex_kluge); +     THREADS_ALLOW();    while(m->key) co_wait(& m->condition, & mutex_kluge);    OB2KEY(o)->mut=m;
212:    o=clone_object(mutex_key,0);    m=THIS_MUTEX;    +  mt_lock(& mutex_kluge); +     if(m->key && OB2KEY(m->key)->owner == thread_id) -  +  { +  mt_unlock(&mutex_kluge);    error("Recursive mutex locks!\n"); -  -  mt_lock(& mutex_kluge); +  }    THREADS_ALLOW();    if(!m->key)    {
320:    THREADS_DISALLOW();    pop_stack();    } else { +  mt_lock(&mutex_kluge);    THREADS_ALLOW(); -  co_wait(c, 0); +  co_wait(c, &mutex_kluge); +  mt_unlock(&mutex_kluge);    THREADS_DISALLOW();    }   }