Fixed initialization and thread problems in top - changed by Jim

This commit is contained in:
Jan Görig 2011-04-18 16:06:54 +02:00
parent aac0de8994
commit 2a2fa20656

42
top.c
View File

@ -194,7 +194,7 @@ static int *PHash_sav = HHash_one, // alternating 'old/new' hash tables
* Create string from cgroup array -- * Create string from cgroup array --
* ( eventually to find a home in libproc ? ) */ * ( eventually to find a home in libproc ? ) */
static void parse_cgroup (char *dst, size_t max, const proc_t *p) { static void parse_cgroup (char *dst, size_t max, const proc_t *p) {
int whackable_int; int whackable_int = max;
char *ccgroup, *endp = dst; char *ccgroup, *endp = dst;
*dst = '\0'; *dst = '\0';
@ -1025,7 +1025,7 @@ static char *linein (const char *prompt) {
} }
putp(fmtmk("%s%s%s", tg2(beg, Msg_row), Cap_clr_eol, buf)); putp(fmtmk("%s%s%s", tg2(beg, Msg_row), Cap_clr_eol, buf));
putp(tg2(beg+pos, Msg_row)); putp(tg2(beg+pos, Msg_row));
} while (kbd_ENTER != key && kbd_ESC != key); } while (key && kbd_ENTER != key && kbd_ESC != key);
return buf; return buf;
#undef sqzSTR #undef sqzSTR
@ -1661,7 +1661,7 @@ static void fields_utility (void) {
default: // keep gcc happy default: // keep gcc happy
break; break;
} }
} while ('q' != key && kbd_ESC != key); } while (key && 'q' != key && kbd_ESC != key);
putp(Cap_curs_norm); putp(Cap_curs_norm);
#undef unSCRL #undef unSCRL
#undef swapEM #undef swapEM
@ -1939,15 +1939,16 @@ static proc_t **procs_refresh (proc_t **ppt) {
// i) Allocated Chunks: *Existing* table; refresh + reuse // i) Allocated Chunks: *Existing* table; refresh + reuse
if (!Thread_mode) { if (!Thread_mode) {
while (curmax < savmax) { while (curmax < savmax) {
if (ppt[curmax]->cmdline) { if (ppt[curmax]->cmdline || ppt[curmax]->cgroup) {
// skip if thread mode was never enabled (see note below) if (threadshown) { // skip if never used (see note below)
if (threadshown) { for (i = curmax + 1; i < savmax; i++) {
for (i = curmax + 1; i < savmax; i++) if (ppt[i]->cmdline == ppt[curmax]->cmdline) ppt[i]->cmdline = NULL;
if (ppt[i]->cmdline == ppt[curmax]->cmdline) if (ppt[i]->cgroup == ppt[curmax]->cgroup) ppt[i]->cgroup = NULL;
ppt[i]->cmdline = NULL; }
} }
free(*ppt[curmax]->cmdline); if (ppt[curmax]->cmdline) free(*ppt[curmax]->cmdline);
ppt[curmax]->cmdline = NULL; if (ppt[curmax]->cgroup) free(*ppt[curmax]->cgroup);
ppt[curmax]->cmdline = ppt[curmax]->cgroup = NULL;
} }
if (!(ptask = readproc(PT, ppt[curmax]))) break; if (!(ptask = readproc(PT, ppt[curmax]))) break;
prochlp(ptask); // tally & complete this proc_t prochlp(ptask); // tally & complete this proc_t
@ -1958,15 +1959,16 @@ static proc_t **procs_refresh (proc_t **ppt) {
while (curmax < savmax) { while (curmax < savmax) {
if (!(ptask = readproc(PT, NULL))) break; if (!(ptask = readproc(PT, NULL))) break;
while (curmax < savmax) { while (curmax < savmax) {
if (ppt[curmax]->cmdline) { if (ppt[curmax]->cmdline || ppt[curmax]->cgroup) {
/* note: threads share the same cmdline storage. so we must look /* note: threads share some of the same storage, so we must look
through the rest of our table for duplicate ref's... */ through the rest of our table for duplicate ref's... */
for (i = curmax + 1; i < savmax; i++) for (i = curmax + 1; i < savmax; i++) {
if (ppt[i]->cmdline == ppt[curmax]->cmdline) if (ppt[i]->cmdline == ppt[curmax]->cmdline) ppt[i]->cmdline = NULL;
ppt[i]->cmdline = NULL; if (ppt[i]->cgroup == ppt[curmax]->cgroup) ppt[i]->cgroup = NULL;
/* ...but free only once ! */ } /* ...but free only once ! */
free(*ppt[curmax]->cmdline); if (ppt[curmax]->cmdline) free(*ppt[curmax]->cmdline);
ppt[curmax]->cmdline = NULL; if (ppt[curmax]->cgroup) free(*ppt[curmax]->cgroup);
ppt[curmax]->cmdline = ppt[curmax]->cgroup = NULL;
} }
if (!(pthrd = readtask(PT, ptask, ppt[curmax]))) break; if (!(pthrd = readtask(PT, ptask, ppt[curmax]))) break;
threadshown = 1; threadshown = 1;
@ -3402,7 +3404,7 @@ static int window_show (proc_t **ppt, WIN_t *q, int wmax) {
qsort(ppt, Frame_maxtask, sizeof(proc_t *), Fieldstab[q->rc.sortindx].sort); qsort(ppt, Frame_maxtask, sizeof(proc_t *), Fieldstab[q->rc.sortindx].sort);
i = q->begtask; i = q->begtask;
if (i > Frame_maxtask - 1) i = q->begtask = Frame_maxtask - 1; if (i >= Frame_maxtask) i = q->begtask = Frame_maxtask - 1;
lwin = 1; // 1 for the ol' column header lwin = 1; // 1 for the ol' column header
wmax = winMIN(wmax, q->winlines+1); // ditto for winlines, too wmax = winMIN(wmax, q->winlines+1); // ditto for winlines, too