summaryrefslogtreecommitdiff
path: root/core/procps/procps-3.2.8-threads.patch
blob: 2491aa4c00133a358b15dcfd4bb4fa122a841e76 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
diff -up procps-3.2.8/top.c.threads procps-3.2.8/top.c
--- procps-3.2.8/top.c.threads	2009-10-01 07:14:43.000000000 -0400
+++ procps-3.2.8/top.c	2009-10-05 14:05:00.000000000 -0400
@@ -1138,6 +1138,7 @@ static proc_t **procs_refresh (proc_t **
 #define ENTsz  sizeof(proc_t)
    static unsigned savmax = 0;          // first time, Bypass: (i)
    proc_t *ptsk = (proc_t *)-1;         // first time, Force: (ii)
+   proc_t *saved_ptsk;
    unsigned curmax = 0;                 // every time  (jeeze)
    PROCTAB* PT;
    static int show_threads_was_enabled = 0; // optimization
@@ -1172,6 +1173,10 @@ static proc_t **procs_refresh (proc_t **
       while (curmax < savmax) {
          proc_t *ttsk;
          if (unlikely(!(ptsk = readproc(PT, NULL)))) break;
+	 if(!show_threads_was_enabled)
+             saved_ptsk = ptsk;
+	 else
+	     saved_ptsk = NULL;
          show_threads_was_enabled = 1;
          while (curmax < savmax) {
             unsigned idx;
@@ -1189,7 +1194,7 @@ static proc_t **procs_refresh (proc_t **
             prochlp(ttsk);
             ++curmax;
          }
-         free(ptsk);  // readproc() proc_t not used
+         if(!saved_ptsk) free(ptsk);  // readproc() proc_t not used
       }
    }
 
@@ -1208,7 +1213,8 @@ static proc_t **procs_refresh (proc_t **
    else {                          // show each thread in a process separately
       while (ptsk) {
          proc_t *ttsk;
-         if (likely(ptsk = readproc(PT, NULL))) {
+         if (likely(ptsk = readproc(PT, NULL)) || 
+             unlikely(saved_ptsk && (ptsk = saved_ptsk)) ) {
             show_threads_was_enabled = 1;
             while (1) {
                table = alloc_r(table, (curmax + 1) * PTRsz);
@@ -1216,6 +1222,7 @@ static proc_t **procs_refresh (proc_t **
                prochlp(ttsk);
                table[curmax++] = ttsk;
             }
+            saved_ptsk = NULL;
             free(ptsk);   // readproc() proc_t not used
          }
       }