pike.git / src / threads.c

version» Context lines:

pike.git/src/threads.c:1:   /*   || 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;      #ifdef _REENTRANT   #include "threads.h"   #include "array.h"   #include "mapping.h"   #include "object.h"   #include "pike_macros.h"
pike.git/src/threads.c:929:      struct mutex_storage   {    COND_T condition;    struct object *key;   };      struct key_storage   {    struct mutex_storage *mut; +  struct object *mutex_obj;    struct object *owner;    int initialized;   };      #define OB2KEY(X) ((struct key_storage *)((X)->storage))      /*! @class Mutex    *!    *! @[Mutex] is a class that implements mutual exclusion locks.    *! Mutex locks are used to prevent multiple threads from simultaneously
pike.git/src/threads.c:1054:    {    SWAP_OUT_CURRENT_THREAD();    THREADS_FPRINTF(1, (stderr,"WAITING TO LOCK m:%08x\n",(unsigned int)m));    co_wait_interpreter(& m->condition);    SWAP_IN_CURRENT_THREAD();    check_threads_etc();    }while(m->key);    }    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) {    debug_list_all_threads();    Pike_fatal("thread_for_id() (or Pike_interpreter.thread_id) failed! %p != %p\n",thread_for_id(th_self()),Pike_interpreter.thread_id) ;    } )       THREADS_FPRINTF(1, (stderr, "LOCK k:%08x, m:%08x(%08x), t:%08x\n",    (unsigned int)OB2KEY(o),    (unsigned int)m,
pike.git/src/threads.c:1120:    case 2:    case 1:    break;    }       o=clone_object(mutex_key,0);       if(!m->key)    {    OB2KEY(o)->mut=m; +  add_ref (OB2KEY(o)->mutex_obj = Pike_fp->current_object);    m->key=o;    i=1;    }       pop_n_elems(args);    if(i)    {    push_object(o);    } else {    destruct(o);
pike.git/src/threads.c:1155:    struct mutex_storage *m = THIS_MUTEX;       pop_n_elems(args);       if (m->key && OB2KEY(m->key)->owner)    ref_push_object(OB2KEY(m->key)->owner);    else    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.    *!    *! @seealso    *! @[Thread()]    */   PMOD_EXPORT void f_mutex_locking_key(INT32 args)   {    struct mutex_storage *m = THIS_MUTEX;
pike.git/src/threads.c:1199:      /*! @endclass    */      #define THIS_KEY ((struct key_storage *)(CURRENT_STORAGE))   void init_mutex_key_obj(struct object *o)   {    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;   }      void exit_mutex_key_obj(struct object *o)   {    THREADS_FPRINTF(1, (stderr, "UNLOCK k:%08x m:(%08x) t:%08x o:%08x\n",    (unsigned int)THIS_KEY,    (unsigned int)THIS_KEY->mut,    (unsigned int)Pike_interpreter.thread_id,
pike.git/src/threads.c:1223: Inside #if defined(PIKE_DEBUG)
     #ifdef PIKE_DEBUG    if(mut->key != o)    Pike_fatal("Mutex unlock from wrong key %p != %p!\n",THIS_KEY->mut->key,o);   #endif    mut->key=0;    if (THIS_KEY->owner) {    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);    }   }      #define THIS_COND ((COND_T *)(CURRENT_STORAGE))      /*! @class Condition    *!    *! Implementation of condition variables.
pike.git/src/threads.c:1804: Inside #if defined(UNIX_THREADS)
     /* function(int:void) */    ADD_EFUN("thread_set_concurrency",f_thread_set_concurrency,tFunc(tInt,tVoid), OPT_SIDE_EFFECT);   #endif       START_NEW_PROGRAM_ID(THREAD_MUTEX_KEY);    mutex_key_offset = ADD_STORAGE(struct key_storage);    /* 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;    add_ref(mutex_key);    end_class("mutex_key", 0);    mutex_key->flags|=PROGRAM_DESTRUCT_IMMEDIATE;   #ifdef PIKE_DEBUG    if(!mutex_key)    Pike_fatal("Failed to initialize mutex_key program!\n");   #endif