pike.git / src / threads.c

version» Context lines:

pike.git/src/threads.c:3056:   /*! @endclass    */      enum rwmux_kind    {    RWMUX_NONE = 0,    RWMUX_TRY_READ = RWMUX_NONE,    RWMUX_READ,    RWMUX_DOWNGRADED,    RWMUX_TRY_WRITE = RWMUX_DOWNGRADED, +  RWMUX_UPGRADING,    RWMUX_WRITE,    };      struct rwmutex_key_storage   { -  +  struct object *self; /* NOT ref-counted! */    struct rwmutex_storage *rwmutex;    struct object *rwmutex_obj;    struct thread_state *owner;    struct object *owner_obj;    struct rwmutex_key_storage *prev;    struct rwmutex_key_storage *next;    enum rwmux_kind kind;   };      /*! @class RWMutex
pike.git/src/threads.c:3185:    */   static void f_rwmutex_try_write_lock(INT32 args)   {    ref_push_object_inherit(Pike_fp->current_object,    Pike_fp->context -    Pike_fp->current_object->prog->inherits);    push_int(RWMUX_TRY_WRITE);    push_object(clone_object(rwmutex_key_program, 2));   }    + /*! @decl array(Thread.Thread) current_locking_threads() +  *! +  *! Return an array with the treads that are holding +  *! keys to the mutex. +  *! +  *! @seealso +  *! @[current_locking_threads()] +  */ + static void f_rwmutex_current_locking_threads(INT32 args) + { +  struct rwmutex_storage *m = THIS_RWMUTEX; +  struct rwmutex_key_storage *key; +  int count = 0; +  for (key = m->key; key; key = key->next) { +  if (key->owner_obj && key->owner_obj->prog) { +  ref_push_object(key->owner_obj); +  count++; +  } +  } +  f_aggregate(count); + } +  + /*! @decl array(Thread.Thread) current_locking_keys() +  *! +  *! Return an array with the currently active keys +  *! to the mutex. +  *! +  *! @seealso +  *! @[current_locking_threads()] +  */ + static void f_rwmutex_current_locking_keys(INT32 args) + { +  struct rwmutex_storage *m = THIS_RWMUTEX; +  struct rwmutex_key_storage *key; +  int count = 0; +  for (key = m->key; key; key = key->next) { +  if (key->self && key->self->prog) { +  ref_push_object(key->self); +  count++; +  } +  } +  f_aggregate(count); + } +    /*! @decl string _sprintf(int c)    *!    *! Describes the mutex including the thread(s) that currently hold    *! locks (if any).    */   static void f_rwmutex__sprintf(INT32 args)   {    struct rwmutex_storage *m = THIS_RWMUTEX;    int c = 0;    struct rwmutex_key_storage *key;
pike.git/src/threads.c:3235:    }    }    push_static_text(" */)");       f_add(Pike_sp - save_sp);   }      /*! @endclass   */    + /*! @class RWKey +  */ +    #define THIS_RWKEY ((struct rwmutex_key_storage *)(CURRENT_STORAGE))   static void init_rwmutex_key_obj(struct object *UNUSED(o))   { -  +  /* NB: This function is also called from create(), so it +  * needs to support being called multiple times on +  * the same storage. +  */ +  THIS_RWKEY->self = Pike_fp->current_object;    if (THIS_RWKEY->owner_obj) {    free_object(THIS_RWKEY->owner_obj);    }    THIS_RWKEY->owner = Pike_interpreter.thread_state;    THIS_RWKEY->owner_obj = Pike_interpreter.thread_state->thread_obj;    if (THIS_RWKEY->owner_obj)    add_ref(THIS_RWKEY->owner_obj);    THIS_RWKEY->kind = RWMUX_NONE;   }    - /*! @class RWKey -  */ -  +    static void exit_rwmutex_key_obj(struct object *UNUSED(o))   {    if (THIS_RWKEY->rwmutex) {    struct rwmutex_storage *rwmutex = THIS_RWKEY->rwmutex;    struct object *rwmutex_obj = THIS_RWKEY->rwmutex_obj;       THIS_RWKEY->rwmutex = NULL;    THIS_RWKEY->rwmutex_obj = NULL;       if (THIS_RWKEY->owner_obj) {
pike.git/src/threads.c:4683:    START_NEW_PROGRAM_ID(THREAD_RWMUTEX);    ADD_STORAGE(struct rwmutex_storage);    ADD_FUNCTION("read_lock", f_rwmutex_read_lock,    tFunc(tNone, tObjIs_THREAD_RWMUTEX_KEY), 0);    ADD_FUNCTION("try_read_lock", f_rwmutex_try_read_lock,    tFunc(tNone, tObjIs_THREAD_RWMUTEX_KEY), 0);    ADD_FUNCTION("write_lock", f_rwmutex_write_lock,    tFunc(tNone, tObjIs_THREAD_RWMUTEX_KEY), 0);    ADD_FUNCTION("try_write_lock", f_rwmutex_try_write_lock,    tFunc(tNone, tObjIs_THREAD_RWMUTEX_KEY), 0); +  ADD_FUNCTION("current_locking_threads", f_rwmutex_current_locking_threads, +  tFunc(tNone, tArr(tObjImpl_THREAD_ID)), 0); +  ADD_FUNCTION("current_locking_keys", f_rwmutex_current_locking_keys, +  tFunc(tNone, tArr(tObjImpl_THREAD_RWMUTEX_KEY)), 0);    ADD_FUNCTION("_sprintf", f_rwmutex__sprintf,    tFunc(tOr(tInt, tVoid), tStr), ID_PROTECTED);    set_init_callback(init_rwmutex_obj);    set_exit_callback(exit_rwmutex_obj);    rwmutex_program = Pike_compiler->new_program;    add_ref(rwmutex_program);    end_class("RWMutex", 0);       START_NEW_PROGRAM_ID(THREAD_CONDITION);    ADD_STORAGE(struct pike_cond);