pike.git / src / threads.c

version» Context lines:

pike.git/src/threads.c:1:   #include "global.h" - RCSID("$Id: threads.c,v 1.175 2004/03/08 16:49:58 grubba Exp $"); + RCSID("$Id: threads.c,v 1.176 2004/03/09 14:12:58 grubba 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:842:      struct mutex_storage   {    COND_T condition;    /* Key-related data. */    struct object *owner; /* NULL: Unlocked. other: locked with owner. */   };      struct key_storage   { -  struct mutex_storage *mut; +  struct mutex_storage *mut; /* Only valid if mutex_obj is not destructed. */    struct object *mutex_obj;   };      #define OB2KEY(X) ((struct key_storage *)((X)->storage))      void f_mutex_lock(INT32 args)   {    struct mutex_storage *m;    struct object *o;    INT_TYPE type;
pike.git/src/threads.c:916:    co_wait_interpreter(& m->condition);    while (threads_disabled) {    THREADS_FPRINTF(1, (stderr,    "f_mutex_lock(): Threads disabled\n"));    co_wait_interpreter(&threads_disabled_change);    }    }while(m->owner);    SWAP_IN_CURRENT_THREAD();    }    add_ref(m->owner = Pike_interpreter.thread_id); /* Locked. */ -  OB2KEY(o)->mut = m; +     add_ref(OB2KEY(o)->mutex_obj = Pike_fp->current_object); -  +  OB2KEY(o)->mut = m;       DO_IF_DEBUG( if(thread_for_id(th_self()) != Pike_interpreter.thread_id)    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, t:%08x\n",    (unsigned int)OB2KEY(o),    (unsigned int)m,    (unsigned int)Pike_interpreter.thread_id));    pop_n_elems(args);    push_object(o);
pike.git/src/threads.c:969:    case 2:    case 1:    break;    }       o=clone_object(mutex_key,0);       if(!m->owner)    {    add_ref(m->owner = Pike_interpreter.thread_id); -  OB2KEY(o)->mut=m; +     add_ref(OB2KEY(o)->mutex_obj = Pike_fp->current_object); -  +  OB2KEY(o)->mut=m;    pop_n_elems(args);    push_object(o);    } else {    pop_n_elems(args);    destruct(o);    free_object(o);    push_int(0);    }   }   
pike.git/src/threads.c:1002:    free_object(THIS_MUTEX->owner);    }    THIS_MUTEX->owner = NULL;    co_destroy(& THIS_MUTEX->condition);   }      #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)); +  (unsigned int)THIS_KEY, +  (unsigned int)Pike_interpreter.thread_id));    THIS_KEY->mut = NULL;    THIS_KEY->mutex_obj = NULL;   }      void exit_mutex_key_obj(struct object *o)   { -  +  struct mutex_storage *mut; +     THREADS_FPRINTF(1, (stderr, "UNLOCK k:%08x m:(%08x) t:%08x\n",    (unsigned int)THIS_KEY,    (unsigned int)THIS_KEY->mut,    (unsigned int)Pike_interpreter.thread_id)); -  if(THIS_KEY->mut) +  +  if((mut = THIS_KEY->mut) && +  // Don't look at mut if the mutex object has been destructed. +  (THIS_KEY->mutex_obj) && (THIS_KEY->mutex_obj->prog))    { -  struct mutex_storage *mut = THIS_KEY->mut; +  struct object *owner = mut->owner;    -  if (mut->owner) { -  free_object(mut->owner); +  THIS_KEY->mut = NULL;    mut->owner = NULL; -  } +     co_signal(& mut->condition); -  THIS_KEY->mut = NULL; +  +  if (owner) { +  free_object(mut->owner);    } -  +  }    if (THIS_KEY->mutex_obj) {    free_object(THIS_KEY->mutex_obj);    THIS_KEY->mutex_obj = NULL;    }   }      #define THIS_COND ((COND_T *)(CURRENT_STORAGE))   void f_cond_wait(INT32 args)   {    COND_T *c;