Branch: Tag:

2002-10-28

2002-10-28 21:48:09 by Martin Stjernholm <mast@lysator.liu.se>

Added a reference from MutexKey to the mutex object it holds, so that
the latter won't be refcount garbed (which causes both to be
destructed) if there are no other references.

Rev: src/threads.c:1.189

2:   || This file is part of Pike. For copyright information see COPYRIGHT.   || Pike is distributed under GPL, LGPL and MPL. See the file COPYING   || for more information. - || $Id: threads.c,v 1.188 2002/10/11 01:39:38 nilsson Exp $ + || $Id: threads.c,v 1.189 2002/10/28 21:48:09 mast Exp $   */      #include "global.h" - RCSID("$Id: threads.c,v 1.188 2002/10/11 01:39:38 nilsson Exp $"); + RCSID("$Id: threads.c,v 1.189 2002/10/28 21:48:09 mast Exp $");      PMOD_EXPORT int num_threads = 1;   PMOD_EXPORT int threads_disabled = 0;
936:   struct key_storage   {    struct mutex_storage *mut; +  struct object *mutex_obj;    struct object *owner;    int initialized;   };
1061:    }    m->key=o;    OB2KEY(o)->mut=m; +  add_ref (OB2KEY(o)->mutex_obj = Pike_fp->current_object);       DO_IF_DEBUG(    if(thread_for_id(th_self()) != Pike_interpreter.thread_id) {
1127:    if(!m->key)    {    OB2KEY(o)->mut=m; +  add_ref (OB2KEY(o)->mutex_obj = Pike_fp->current_object);    m->key=o;    i=1;    }
1162:    push_int(0);   }    - /*! @decl Thread.Thread current_locking_key() + /*! @decl Thread.MutexKey current_locking_key()    *!    *! This mutex method returns the key object currently governing    *! the lock on this mutex. 0 is returned if the mutex isn't locked.
1206:    THREADS_FPRINTF(1, (stderr, "KEY k:%08x, o:%08x\n",    (unsigned int)THIS_KEY, (unsigned int)Pike_interpreter.thread_id));    THIS_KEY->mut=0; +  THIS_KEY->mutex_obj = NULL;    add_ref(THIS_KEY->owner=Pike_interpreter.thread_id);    THIS_KEY->initialized=1;   }
1230:    free_object(THIS_KEY->owner);    THIS_KEY->owner=0;    } +  free_object (THIS_KEY->mutex_obj);    THIS_KEY->mut=0; -  +  THIS_KEY->mutex_obj = NULL;    THIS_KEY->initialized=0;    co_signal(& mut->condition);    }
1811:    /* This is needed to allow the gc to find the possible circular reference.    * It also allows a thread to take over ownership of a key.    */ -  map_variable("_owner", "object", 0, -  mutex_key_offset + OFFSETOF(key_storage, owner), T_OBJECT); +  PIKE_MAP_VARIABLE("_owner", mutex_key_offset + OFFSETOF(key_storage, owner), +  tObjIs_THREAD_ID, T_OBJECT, 0); +  PIKE_MAP_VARIABLE("_mutex", mutex_key_offset + OFFSETOF(key_storage, mutex_obj), +  tObjIs_THREAD_MUTEX, T_OBJECT, ID_STATIC|ID_PRIVATE);    set_init_callback(init_mutex_key_obj);    set_exit_callback(exit_mutex_key_obj);    mutex_key=Pike_compiler->new_program;