pike.git / src / threads.c

version» Context lines:

pike.git/src/threads.c:2119:    * key object when the key is destructed.    */      struct mutex_storage   {    COND_T condition;    struct object *key;    int num_waiting;   };    + enum key_kind + { +  KEY_UNINITIALIZED = 0, +  KEY_INITIALIZED, + }; +    struct key_storage   {    struct mutex_storage *mut;    struct object *mutex_obj;    struct thread_state *owner;    struct object *owner_obj; -  int initialized; +  enum key_kind kind;   };      #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    *! execute sections of code which access or change shared data. The basic    *! operations for a mutex is locking and unlocking. If a thread attempts
pike.git/src/threads.c:2525:    THREADS_FPRINTF(1, "KEY k:%p, t:%p\n",    THIS_KEY, Pike_interpreter.thread_state);   #ifdef PIKE_NULL_IS_SPECIAL    THIS_KEY->mut=0;    THIS_KEY->mutex_obj = NULL;   #endif    THIS_KEY->owner = Pike_interpreter.thread_state;    THIS_KEY->owner_obj = Pike_interpreter.thread_state->thread_obj;    if (THIS_KEY->owner_obj)    add_ref(THIS_KEY->owner_obj); -  THIS_KEY->initialized=1; +  THIS_KEY->kind = KEY_INITIALIZED;   }      void exit_mutex_key_obj(struct object *DEBUGUSED(o))   {    THREADS_FPRINTF(1, "UNLOCK k:%p m:(%p) t:%p o:%p\n",    THIS_KEY, THIS_KEY->mut,    Pike_interpreter.thread_state, THIS_KEY->owner);    if(THIS_KEY->mut)    {    struct mutex_storage *mut = THIS_KEY->mut;
pike.git/src/threads.c:2555:   #endif    mut->key=0;    if (THIS_KEY->owner) {    THIS_KEY->owner = NULL;    }    if (THIS_KEY->owner_obj) {    free_object(THIS_KEY->owner_obj);    THIS_KEY->owner_obj=0;    }    THIS_KEY->mut=0; -  THIS_KEY->initialized=0; +  THIS_KEY->kind = KEY_UNINITIALIZED;    mutex_obj = THIS_KEY->mutex_obj;    THIS_KEY->mutex_obj = NULL;       if (mut->num_waiting) {    THREADS_ALLOW();    co_signal(&mut->condition);       /* Try to wake up the waiting thread(s) immediately    * in an attempt to avoid starvation.    */
pike.git/src/threads.c:3333:    seconds = (INT_TYPE) fsecs;    nanos = (INT_TYPE)((fsecs - seconds)*1000000000);    } else {    /* FIXME: Support bignum nanos. */    get_all_args(NULL, args, "%o%i%i", &key, &seconds, &nanos);    }       c = THIS_COND;       if ((key->prog != mutex_key) || -  (!(OB2KEY(key)->initialized)) || +  (!(OB2KEY(key)->kind)) ||    (!(mut = OB2KEY(key)->mut)) ||    (c->mutex_obj && OB2KEY(key)->mutex_obj &&    (OB2KEY(key)->mutex_obj != c->mutex_obj))) {    Pike_error("Bad argument 1 to wait()\n");    }       if(args > 1) {    pop_n_elems(args - 1);    args = 1;    }