pike.git / src / threads.c

version» Context lines:

pike.git/src/threads.c:3019:    }   #endif   }      /*! @endclass    */      /*! @class MutexKey    *!    *! Objects of this class are returned by @[Mutex()->lock()] -  *! and @[Mutex()->trylock()]. They are also passed as arguments +  *! and @[Mutex()->trylock()] et al. They are also passed as arguments    *! to @[Condition()->wait()].    *!    *! As long as they are held, the corresponding mutex will be locked.    *!    *! The corresponding mutex will be unlocked when the object    *! is destructed (eg by not having any references left).    *!    *! @seealso    *! @[Mutex], @[Condition]    */
pike.git/src/threads.c:3123:    THREADS_DISALLOW();    } else if (mutex_obj && !mutex_obj->prog) {    co_destroy (&mut->condition);    }       if (mutex_obj)    free_object(mutex_obj);    }   }    + /*! @decl protected string _sprintf(int c) */   static void f_mutex_key__sprintf(INT32 args)   {    int c = 0;    if(args>0 && TYPEOF(Pike_sp[-args]) == PIKE_T_INT)    c = Pike_sp[-args].u.integer;    pop_n_elems (args);    if(c != 'O') {    push_undefined();    return;    }    if (THIS_KEY->mutex_obj) {    push_text("Thread.MutexKey(/* %O */)");    ref_push_object(THIS_KEY->mutex_obj);    f_sprintf(2);    } else {    push_text("Thread.MutexKey(/* Unlocked */)");    }   }    -  + /*! @decl void downgrade() +  *! +  *! Downgrade an exclusive lock into a shared lock. +  *! +  *! A downgraded lock may be upgraded back to an exclusive lock +  *! by calling @[upgrade()] or @[try_upgrade()]. +  *! +  *! @seealso +  *! @[upgrade()], @[try_upgrade()] +  */   static void f_mutex_key_downgrade(INT32 args)   {    struct key_storage *key = THIS_KEY;       if (key->kind < KEY_PENDING) return;       if (key->kind == KEY_PENDING) {    Pike_error("It is not possible to downgrade a key that is waiting.\n");    }       key->kind = KEY_DOWNGRADED;       co_broadcast(&key->mut->condition);   }    -  + /*! @decl void upgrade() +  *! +  *! Upgrade a downgraded lock into an exclusive lock. +  *! +  *! Waits until all concurrent shared locks are released, +  *! and upgrades this lock into being an exclusive lock. +  *! Any attempts to make new shared locks will block as +  *! soon as this function is called. +  *! +  *! @seealso +  *! @[downgrade()], @[try_upgrade()] +  */   static void f_mutex_key_upgrade(INT32 args)   {    struct key_storage *key = THIS_KEY;    struct mutex_storage *m = key->mut;       if (key->kind >= KEY_PENDING) return;       if (key->kind != KEY_DOWNGRADED) {    Pike_error("Upgrade is not allowed for non-degraded mutex keys.\n");    }
pike.git/src/threads.c:3193:    co_wait_interpreter(& m->condition);    SWAP_IN_CURRENT_THREAD();    check_threads_etc();    } while (key->next);    m->num_waiting--;    }       key->kind = KEY_EXCLUSIVE;   }    + /*! @decl int(0..1) try_upgrade() +  *! +  *! Try to upgrade a downgraded lock into an exclusive lock. +  *! +  *! @returns +  *! @int +  *! @value 0 +  *! Returns @expr{0@} (zero) if there are other concurrent +  *! shared locks active. +  *! @value 1 +  *! Returns @expr{1@} if this is the only active lock, and +  *! upgrading it to being exclusive succeeded. +  *! @endint +  *! +  *! @seealso +  *! @[downgrade()], @[upgrade()] +  */   static void f_mutex_key_try_upgrade(INT32 args)   {    struct key_storage *key = THIS_KEY;       if (key->kind >= KEY_PENDING) {    push_int(1);    return;    }       if (key->kind != KEY_DOWNGRADED) {