RPM Package Manager, CVS Repository http://rpm5.org/cvs/ ____________________________________________________________________________
Server: rpm5.org Name: Jeff Johnson Root: /v/rpm/cvs Email: j...@rpm5.org Module: rpm Date: 16-Mar-2009 14:36:25 Branch: HEAD Handle: 2009031613362401 Modified files: rpm CHANGES rpm/rpmio rpmzlog.c rpmzlog.h Log: - jbj: zlog: rework trace log with a refcount mutex instead. Summary: Revision Changes Path 1.2821 +1 -0 rpm/CHANGES 2.4 +82 -41 rpm/rpmio/rpmzlog.c 2.3 +15 -14 rpm/rpmio/rpmzlog.h ____________________________________________________________________________ patch -p0 <<'@@ .' Index: rpm/CHANGES ============================================================================ $ cvs diff -u -r1.2820 -r1.2821 CHANGES --- rpm/CHANGES 14 Mar 2009 23:46:20 -0000 1.2820 +++ rpm/CHANGES 16 Mar 2009 13:36:24 -0000 1.2821 @@ -1,5 +1,6 @@ 5.2a3 -> 5.2a4: + - jbj: zlog: rework trace log with a refcount mutex instead. - proyvind: do lazy mkdir of %_topdir, %_builddir, %_rpmdir & %_srcrpmdir when doing '--rebuild' so that it should mostly work easily for user. - proyvind: make it possible to set preferred build architectures when using @@ . patch -p0 <<'@@ .' Index: rpm/rpmio/rpmzlog.c ============================================================================ $ cvs diff -u -r2.3 -r2.4 rpmzlog.c --- rpm/rpmio/rpmzlog.c 7 Mar 2009 20:27:10 -0000 2.3 +++ rpm/rpmio/rpmzlog.c 16 Mar 2009 13:36:25 -0000 2.4 @@ -47,6 +47,8 @@ #include "debug.h" +static int _rpmzlog_debug = 0; + /*...@access rpmzMsg @*/ /*...@access rpmzLog @*/ @@ -55,27 +57,36 @@ /* maximum log entry length */ #define _RPMZLOG_MAXMSG 256 -rpmzLog rpmzLogInit(struct timeval *tv) +rpmzLog rpmzLogLink(rpmzLog zlog) { - rpmzLog zlog = xcalloc(1, sizeof(*zlog)); + long nrefs; - if (zlog->msg_tail == NULL) { -/*...@-mustfreeonly@*/ - zlog->msg_lock = yarnNewLock(0); - zlog->msg_head = NULL; - zlog->msg_tail = &zlog->msg_head; -/*...@=mustfreeonly@*/ - /* starting time for log entries */ - if (tv != NULL) { -/*...@-assignexpose@*/ - zlog->start = *tv; /* structure assignment */ -/*...@=assignexpose@*/ - } else - (void) gettimeofday(&zlog->start, NULL); - } + if (zlog == NULL) + return NULL; + yarnPossess(zlog->use); + nrefs = yarnPeekLock(zlog->use); +if (_rpmzlog_debug) +fprintf(stderr, " ++ zlog %p[%ld]\n", zlog, nrefs+1); + yarnTwist(zlog->use, BY, 1); return zlog; } +rpmzLog rpmzLogNew(struct timeval *tv) +{ + rpmzLog zlog = xcalloc(1, sizeof(*zlog)); + + zlog->use = yarnNewLock(0); + zlog->msg_head = NULL; + zlog->msg_tail = &zlog->msg_head; + + /* starting time for log entries */ + if (tv != NULL) + zlog->start = *tv; /* structure assignment */ + else + (void) gettimeofday(&zlog->start, NULL); + return rpmzLogLink(zlog); +} + void rpmzLogAdd(rpmzLog zlog, char *fmt, ...) { rpmzMsg me; @@ -84,7 +95,8 @@ char msg[_RPMZLOG_MAXMSG]; int xx; - if (zlog == NULL) return; + if (zlog == NULL) + return; xx = gettimeofday(&now, NULL); me = xmalloc(sizeof(*me)); @@ -101,34 +113,41 @@ /*...@-mustfreeonly@*/ me->next = NULL; /*...@=mustfreeonly@*/ -assert(zlog->msg_lock != NULL); - yarnPossess(zlog->msg_lock); + +assert(zlog->use != NULL); + yarnPossess(zlog->use); *zlog->msg_tail = me; zlog->msg_tail = &me->next; - yarnTwist(zlog->msg_lock, BY, 1); + zlog->msg_count++; + yarnRelease(zlog->use); } -int rpmzMsgShow(rpmzLog zlog, FILE * fp) +/** + * * 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; - int xx; - if (zlog == NULL || zlog->msg_tail == NULL) + if (zlog == NULL) return 0; - if (fp == NULL) fp = stderr; - yarnPossess(zlog->msg_lock); - me = zlog->msg_head; - if (me == NULL) { - yarnRelease(zlog->msg_lock); + + yarnPossess(zlog->use); + if (zlog->msg_tail == NULL || (me = zlog->msg_head) == NULL) { + yarnRelease(zlog->use); return 0; } zlog->msg_head = me->next; if (me->next == NULL) zlog->msg_tail = &zlog->msg_head; - yarnTwist(zlog->msg_lock, BY, -1); + zlog->msg_count--; + yarnRelease(zlog->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) { @@ -137,7 +156,7 @@ } fprintf(fp, "trace %ld.%06ld %s\n", (long)diff.tv_sec, (long)diff.tv_usec, me->msg); - xx = fflush(fp); + (void) fflush(fp); me->msg = _free(me->msg); me = _free(me); return 1; @@ -145,25 +164,47 @@ rpmzLog rpmzLogFree(rpmzLog zlog) { + long nrefs; rpmzMsg me; if (zlog == NULL) return NULL; - if (zlog->msg_tail != NULL) { - yarnPossess(zlog->msg_lock); - while ((me = zlog->msg_head) != NULL) { - zlog->msg_head = me->next; - me->msg = _free(me->msg); + yarnPossess(zlog->use); + nrefs = yarnPeekLock(zlog->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->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); + 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; } - yarnTwist(zlog->msg_lock, TO, 0); - zlog->msg_lock = yarnFreeLock(zlog->msg_lock); - zlog->msg_tail = NULL; - } - zlog = _free(zlog); + zlog = _free(zlog); + yarnTwist(use, BY, -1); + use = yarnFreeLock(use); + } else + yarnTwist(zlog->use, BY, -1); return NULL; } @@ . patch -p0 <<'@@ .' Index: rpm/rpmio/rpmzlog.h ============================================================================ $ cvs diff -u -r2.2 -r2.3 rpmzlog.h --- rpm/rpmio/rpmzlog.h 12 Mar 2009 20:01:32 -0000 2.2 +++ rpm/rpmio/rpmzlog.h 16 Mar 2009 13:36:25 -0000 2.3 @@ -7,7 +7,7 @@ #include <sys/time.h> /** trace log pointer */ -typedef /*...@abstract@*/ struct rpmzLog_s * rpmzLog; +typedef /*...@abstract@*/ /*...@refcounted@*/ struct rpmzLog_s * rpmzLog; #ifdef _RPMZLOG_INTERNAL #include <yarn.h> @@ -24,13 +24,13 @@ /** trace log */ struct rpmzLog_s { + yarnLock use; /*!< use count -- return to pool when zero */ struct timeval start; /*!< starting time of day for tracing */ /*...@null@*/ rpmzMsg msg_head; /*...@shared@*/ /*...@relnull@*/ rpmzMsg *msg_tail; -/*...@only@*/ /*...@null@*/ - yarnLock msg_lock; + int msg_count; }; #endif /* _RPMZLOG_INTERNAL */ @@ -39,10 +39,18 @@ #endif /** + * Reference the log data. + */ +/*...@newref@*/ +rpmzLog rpmzLogLink(/*...@returned@*/ /*...@null@*/ rpmzLog zlog) + /*...@globals fileSystem, internalState @*/ + /*...@modifies fileSystem, internalState @*/; + +/** * Set up log (call from main thread before other threads launched). */ /*...@only@*/ -rpmzLog rpmzLogInit(/*...@null@*/ struct timeval *tv) +rpmzLog rpmzLogNew(/*...@null@*/ struct timeval *tv) /*...@globals fileSystem, internalState @*/ /*...@modifies fileSystem, internalState @*/; @@ -54,17 +62,10 @@ /*...@modifies zlog, fileSystem, internalState @*/; /** - * Pull entry from trace log and print it, return false if empty. - */ -int rpmzMsgShow(/*...@null@*/ rpmzLog zlog, /*...@null@*/ FILE * fp) - /*...@globals fileSystem, internalState @*/ - /*...@modifies zlog, *fp, fileSystem, internalState @*/; - -/** - * Release log resources (need to do rpmzLogInit() to use again). + * Release a reference to the log data. */ /*...@null@*/ -rpmzLog rpmzLogFree(/*...@only@*/ /*...@null@*/ rpmzLog zlog) +rpmzLog rpmzLogFree(/*...@killref@*/ /*...@null@*/ rpmzLog zlog) /*...@globals fileSystem, internalState @*/ /*...@modifies zlog, fileSystem, internalState @*/; @@ -72,7 +73,7 @@ * Show entries until no more, free log. */ /*...@null@*/ -rpmzLog rpmzLogDump(rpmzLog zlog, /*...@null@*/ FILE * fp) +rpmzLog rpmzLogDump(/*...@killref@*/ /*...@null@*/ rpmzLog zlog, /*...@null@*/ FILE * fp) /*...@globals fileSystem, internalState @*/ /*...@modifies zlog, *fp, fileSystem, internalState @*/; @@ . ______________________________________________________________________ RPM Package Manager http://rpm5.org CVS Sources Repository rpm-cvs@rpm5.org