Esempio n. 1
0
/*@null@*/
void * rpmioFreePoolItem(/*@killref@*/ /*@null@*/ rpmioItem item,
                const char * msg, const char * fn, unsigned ln)
        /*@modifies item @*/
{
    rpmioPool pool;
    if (item == NULL) return NULL;

#ifdef	NOTYET
assert(item->pool != NULL);	/* XXX (*pool->fini) is likely necessary */
#endif
    yarnPossess(item->use);
    if ((pool = item->pool) != NULL && pool->flags && msg != NULL) {
	const char * imsg = (pool->dbg ? (*pool->dbg)((void *)item) : "");
/*@-modfilesys@*/
	fprintf(stderr, "--> %s %p -- %ld %s at %s:%u%s\n", pool->name,
			item, yarnPeekLock(item->use), msg, fn, ln, imsg);
/*@=modfilesys@*/
    }
    if (yarnPeekLock(item->use) <= 1L) {
	if (pool != NULL && pool->fini != NULL)
	    (*pool->fini) ((void *)item);
	VALGRIND_MEMPOOL_FREE(pool, item + 1);
	item = rpmioPutPool(item);
    } else
	yarnTwist(item->use, BY, -1);
/*@-retalias@*/	/* XXX returning the deref'd item is used to detect nrefs = 0 */
    return (void *) item;
/*@=retalias@*/
}
Esempio n. 2
0
rpmzLog rpmzLogFree(rpmzLog zlog)
{
    long nrefs;
    rpmzMsg me;

    if (zlog == NULL)
        return NULL;

    yarnPossess(zlog->_item.use);
    nrefs = yarnPeekLock(zlog->_item.use);
    if (_rpmzlog_debug)
        fprintf(stderr, "    -- zlog %p[%ld]\n", zlog, nrefs);
#ifdef  NOTYET
    assert(nrefs > 0);
#else
    if (nrefs <= 0)
        fprintf(stderr, "==> FIXME: %s: zlog %p[%ld]\n", __FUNCTION__, zlog, nrefs);
#endif
    if (nrefs == 1) {
        yarnLock use = zlog->_item.use;
        if (zlog->msg_tail != NULL) {
            while ((me = zlog->msg_head) != NULL) {
                zlog->msg_head = me->next;
                me->msg = _free(me->msg);
                /*@-compdestroy@*/
                me = _free(me);
                /*@=compdestroy@*/
                zlog->msg_count--;
            }
#ifdef  NOTYET
            assert(zlog->msg_count == 0);
#else
            if (zlog->msg_count != 0)
                fprintf(stderr, "==> FIXME: %s: zlog %p[%ld] count %d\n", __FUNCTION__, zlog, nrefs, zlog->msg_count);
#endif
            zlog->msg_count = 0;
            zlog->msg_tail = NULL;
        }
        zlog = _free(zlog);
        yarnTwist(use, BY, -1);
        use = yarnFreeLock(use);
    } else
        yarnTwist(zlog->_item.use, BY, -1);
    return NULL;
}
Esempio n. 3
0
static rpmvf rpmvfFree(/*@only@*/ rpmvf vf)
	/*@modifies vf @*/
{

    if (vf) {
#ifdef	NOTYET
	yarnPossess(vf->_item.use);
	if (yarnPeekLock(vf->_item.use) <= 1L) {
	    yarnLock use = vf->_item.use;
	    vf->fn = _free(vf->fn);
	    vf = _free(vf);
	    yarnTwist(use, TO, 0);
	    use = yarnFreeLock(use);
	} else
	    yarnTwist(vf->_item.use, BY, -1);
#else
	vf->fn = _free(vf->fn);
	vf = _free(vf);
#endif
    }
    return NULL;
}
Esempio n. 4
0
/*@-internalglobs@*/
rpmioItem rpmioPutPool(rpmioItem item)
{
    rpmioPool pool;

    if ((pool = item->pool) != NULL) {
	yarnPossess(pool->have);
	item->pool = NULL;		/* XXX pool == next */
	*pool->tail = item;
	pool->tail = (void *)&item->pool;/* XXX pool == next */
	yarnTwist(pool->have, BY, 1);
	if (item->use != NULL)
	    yarnTwist(item->use, TO, 0);
	return NULL;
    }

    if (item->use != NULL) {
	yarnTwist(item->use, TO, 0);
	item->use = yarnFreeLock(item->use);
    }
    (void) _free(item);
    return NULL;
}
Esempio n. 5
0
rpmzLog rpmzLogLink(rpmzLog zlog)
{
    long nrefs;

    if (zlog == NULL)
        return NULL;
    yarnPossess(zlog->_item.use);
    nrefs = yarnPeekLock(zlog->_item.use);
    if (_rpmzlog_debug)
        fprintf(stderr, "    ++ zlog %p[%ld]\n", zlog, nrefs+1);
    yarnTwist(zlog->_item.use, BY, 1);
    return zlog;
}
Esempio n. 6
0
/*@-internalglobs@*/
rpmioItem rpmioLinkPoolItem(rpmioItem item, const char * msg,
		const char * fn, unsigned ln)
{
    rpmioPool pool;
    if (item == NULL) return NULL;
    yarnPossess(item->use);
    if ((pool = item->pool) != NULL && pool->flags && msg != NULL) {
	const char * imsg = (pool->dbg ? (*pool->dbg)((void *)item) : "");
/*@-modfilesys@*/
	fprintf(stderr, "--> %s %p ++ %ld %s at %s:%u%s\n", pool->name,
			item, yarnPeekLock(item->use)+1, msg, fn, ln, imsg);
/*@=modfilesys@*/
    }
    yarnTwist(item->use, BY, 1);
    return item;
}
Esempio n. 7
0
/*@-internalglobs@*/
rpmioItem rpmioUnlinkPoolItem(rpmioItem item, const char * msg,
		const char * fn, unsigned ln)
{
    rpmioPool pool;
    if (item == NULL) return NULL;
    yarnPossess(item->use);
    if ((pool = item->pool) != NULL && pool->flags && msg != NULL) {
	const char * imsg = (pool->dbg ? (*pool->dbg)((void *)item) : "");
/*@-modfilesys@*/
	fprintf(stderr, "--> %s %p -- %ld %s at %s:%u%s\n", pool->name,
			item, yarnPeekLock(item->use), msg, fn, ln, imsg);
/*@=modfilesys@*/
    }
    yarnTwist(item->use, BY, -1);
/*@-retalias@*/	/* XXX returning the deref'd item is used to detect nrefs = 0 */
    return item;
/*@=retalias@*/
}
Esempio n. 8
0
/*@-internalglobs@*/
rpmioItem rpmioGetPool(rpmioPool pool, size_t size)
{
    rpmioItem item;

    if (pool != NULL) {
	/* if can't create any more, wait for a space to show up */
	yarnPossess(pool->have);
	if (pool->limit == 0)
	    yarnWaitFor(pool->have, NOT_TO_BE, 0);

	/* if a space is available, pull it from the list and return it */
	if (pool->head != NULL) {
	    item = pool->head;
	    pool->head = item->pool;	/* XXX pool == next */
	    if (pool->head == NULL)
		pool->tail = &pool->head;
	    pool->reused++;
	    item->pool = pool;		/* remember the pool this belongs to */
	    yarnTwist(pool->have, BY, -1);      /* one less in pool */
	    VALGRIND_MEMPOOL_ALLOC(pool,
		item + 1,
		size - sizeof(struct rpmioItem_s));
	    return item;
	}

	/* nothing available, don't want to wait, make a new item */
assert(pool->limit != 0);
	if (pool->limit > 0)
	    pool->limit--;
	pool->made++;
	yarnRelease(pool->have);
    }

    item = xcalloc(1, size);
    item->use = yarnNewLock(0);		/* XXX newref? */
    item->pool = pool;
    VALGRIND_MEMPOOL_ALLOC(pool,
	item + 1,
	size - sizeof(struct rpmioItem_s));
    return item;
}