rpmioPool rpmioFreePool(rpmioPool pool) /*@globals _rpmioPool @*/ /*@modifies _rpmioPool @*/ { if (pool == NULL) { pool = _rpmioPool; _rpmioPool = NULL; } if (pool != NULL) { rpmioItem item; int count = 0; yarnPossess(pool->have); while ((item = pool->head) != NULL) { pool->head = item->pool; /* XXX pool == next */ if (item->use != NULL) item->use = yarnFreeLock(item->use); item = _free(item); count++; } yarnRelease(pool->have); pool->have = yarnFreeLock(pool->have); rpmlog(RPMLOG_DEBUG, D_("pool %s:\treused %d, alloc'd %d, free'd %d items.\n"), pool->name, pool->reused, pool->made, count); #ifdef NOTYET assert(pool->made == count); #else if (pool->made != count) rpmlog(RPMLOG_WARNING, D_("pool %s: FIXME: made %d, count %d\nNote: This is a harmless memory leak discovered while exiting, relax ...\n"), pool->name, pool->made, count); #endif (void) _free(pool); VALGRIND_DESTROY_MEMPOOL(pool); } return NULL; }
void rpmzLogAdd(rpmzLog zlog, const char *fmt, ...) { rpmzMsg me; struct timeval now; va_list ap; char msg[_RPMZLOG_MAXMSG]; int xx; if (zlog == NULL) return; xx = gettimeofday(&now, NULL); me = (rpmzMsg) xmalloc(sizeof(*me)); me->when = now; va_start(ap, fmt); xx = vsnprintf(msg, sizeof(msg)-1, fmt, ap); va_end(ap); msg[sizeof(msg)-1] = '\0'; /*@-mustfreeonly@*/ me->msg = (char *) xmalloc(strlen(msg) + 1); /*@=mustfreeonly@*/ strcpy(me->msg, msg); /*@-mustfreeonly@*/ me->next = NULL; /*@=mustfreeonly@*/ assert(zlog->_item.use != NULL); yarnPossess(zlog->_item.use); *zlog->msg_tail = me; zlog->msg_tail = &me->next; zlog->msg_count++; yarnRelease(zlog->_item.use); }
int rpmrubyRunThread(rpmruby ruby) { int ec = 0; #if defined(HAVE_RUBY_DEFINES_H) /* XXX ruby-1.9.2p0 */ yarnPossess(ruby->ruby_coroutine_lock); yarnPossess(ruby->main_coroutine_lock); /* create a thread to house Ruby */ ruby->thread = yarnLaunchStack((void (*)(void *))rpmrubyThread, ruby, ruby->stack, ruby->nstack); assert(ruby->thread != NULL); /* Relay control to ruby until nothing more to do. */ ruby->more = (ruby->ac > 1); while (ruby->more) _rpmruby_main_to_ruby(ruby); /* Permit ruby thread to run without blocking. */ yarnRelease(ruby->ruby_coroutine_lock); /* Reap the ruby thread. */ ruby->thread = yarnJoin(ruby->thread); ec = 0; #endif /* HAVE_RUBY_DEFINES_H */ return ec; }
/* puts the Ruby coroutine in control */ static void _rpmruby_main_to_ruby(rpmruby ruby) { rpmzLog zlog = ruby->zlog; yarnRelease(ruby->ruby_coroutine_lock); yarnPossess(ruby->main_coroutine_lock); if (_rpmruby_debug < 0) Trace((zlog, "-> %s", __FUNCTION__)); }
/* puts the main C program in control */ static unsigned long _rpmruby_ruby_to_main(rpmruby ruby, unsigned long self) { rpmzLog zlog = ruby->zlog; yarnRelease(ruby->main_coroutine_lock); yarnPossess(ruby->ruby_coroutine_lock); if (_rpmruby_debug < 0) Trace((zlog, "<- %s", __FUNCTION__)); return Qnil; }
static void * rpmrubyThread(void * _ruby) { rpmruby ruby = _ruby; rpmzLog zlog = ruby->zlog; int i; Trace((zlog, "-- %s: running", __FUNCTION__)); _rpmruby_ruby_to_main(ruby, Qnil); for (i = 0; i < 2; i++) _rpmruby_ruby_to_main(ruby, Qnil); { VALUE variable_in_this_stack_frame; uint8_t * b = ruby->stack; uint8_t * e = b + ruby->nstack; /* Start up the ruby interpreter. */ Trace((zlog, "-- %s: interpreter starting", __FUNCTION__)); ruby_sysinit(&ruby->ac, (char ***) &ruby->av); ruby_bind_stack((VALUE *)b, (VALUE *)e); ruby_init_stack(&variable_in_this_stack_frame); ruby_init(); ruby_init_loadpath(); /* allow Ruby script to relay */ rb_define_module_function(rb_mKernel, "relay_from_ruby_to_main", relay_from_ruby_to_main, 0); Trace((zlog, "-- %s: interpreter started", __FUNCTION__)); /* Run file.rb arguments. */ for (i = 1; i < ruby->ac; i++) { if (*ruby->av[i] == '-') /* XXX FIXME: skip options. */ continue; Trace((zlog, "-- %s: require '%s' begin", __FUNCTION__, ruby->av[i])); rpmrubyRunThreadFile(ruby, ruby->av[i], NULL); Trace((zlog, "-- %s: require '%s' end", __FUNCTION__, ruby->av[i])); } /* Terminate the ruby interpreter. */ Trace((zlog, "-- %s: interpreter terminating", __FUNCTION__)); ruby_finalize(); ruby_cleanup(0); Trace((zlog, "-- %s: interpreter terminated", __FUNCTION__)); } /* Report interpreter end to main. */ ruby->more = 0; /* Permit main thread to run without blocking. */ yarnRelease(ruby->main_coroutine_lock); Trace((zlog, "-- %s: ended", __FUNCTION__)); return NULL; }
/** * * Pull entry from trace log and print it, return false if empty. * */ static int rpmzMsgShow(/*@null@*/ rpmzLog zlog, /*@null@*/ FILE * fp) /*@globals fileSystem, internalState @*/ /*@modifies zlog, *fp, fileSystem, internalState @*/ { rpmzMsg me; struct timeval diff; if (zlog == NULL) return 0; if (fp == NULL) fp = stderr; yarnPossess(zlog->_item.use); if (zlog->msg_tail == NULL || (me = zlog->msg_head) == NULL) { yarnRelease(zlog->_item.use); return 0; } zlog->msg_head = me->next; if (me->next == NULL) zlog->msg_tail = &zlog->msg_head; zlog->msg_count--; yarnRelease(zlog->_item.use); diff.tv_usec = me->when.tv_usec - zlog->start.tv_usec; diff.tv_sec = me->when.tv_sec - zlog->start.tv_sec; if (diff.tv_usec < 0) { diff.tv_usec += 1000000L; diff.tv_sec--; } fprintf(fp, "trace %ld.%06ld %s\n", (long)diff.tv_sec, (long)diff.tv_usec, me->msg); (void) fflush(fp); me->msg = _free(me->msg); me = _free(me); return 1; }
/*@-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; }