1:
2:
3:
4:
5:
6:
7:
8:
9:
10:
11:
12:
13:
14:
15:
16:
17:
18:
19:
20:
21:
22: #include "thread_dbP.h"
23:
24:
25: static td_err_e
26: iterate_thread_list (td_thragent_t *ta, td_thr_iter_f *callback,
27: void *cbdata_p, td_thr_state_e state, int ti_pri,
28: psaddr_t head, bool fake_empty)
29: {
30: td_err_e err;
31: psaddr_t next, ofs;
32: void *copy;
33:
34:
35:
36: if (state != TD_THR_ANY_STATE)
37: return TD_OK;
38:
39: err = DB_GET_FIELD (next, ta, head, list_t, next, 0);
40: if (err != TD_OK)
41: return err;
42:
43: if (next == 0 && fake_empty)
44: {
45:
46:
47:
48:
49:
50: td_thrhandle_t th = { ta, 0 };
51: return callback (&th, cbdata_p) != 0 ? TD_DBERR : TD_OK;
52: }
53:
54:
55: err = DB_GET_FIELD_ADDRESS (ofs, ta, 0, pthread, list, 0);
56: if (err != TD_OK)
57: return err;
58:
59: if (ta->ta_sizeof_pthread == 0)
60: {
61: err = _td_check_sizeof (ta, &ta->ta_sizeof_pthread, SYM_SIZEOF_pthread);
62: if (err != TD_OK)
63: return err;
64: }
65: copy = __alloca (ta->ta_sizeof_pthread);
66:
67: while (next != head)
68: {
69: psaddr_t addr, schedpolicy, schedprio;
70:
71: addr = next - (ofs - (psaddr_t) 0);
72: if (next == 0 || addr == 0)
73: return TD_DBERR;
74:
75:
76:
77:
78: if (ps_pdread (ta->ph, addr, copy, ta->ta_sizeof_pthread) != PS_OK)
79: return TD_ERR;
80:
81: err = DB_GET_FIELD_LOCAL (schedpolicy, ta, copy, pthread,
82: schedpolicy, 0);
83: if (err != TD_OK)
84: break;
85: err = DB_GET_FIELD_LOCAL (schedprio, ta, copy, pthread,
86: schedparam_sched_priority, 0);
87: if (err != TD_OK)
88: break;
89:
90:
91:
92:
93: int descr_pri = ((uintptr_t) schedpolicy == SCHED_OTHER
94: ? 0 : (uintptr_t) schedprio);
95: if (descr_pri >= ti_pri)
96: {
97:
98: td_thrhandle_t th;
99: th.th_ta_p = (td_thragent_t *) ta;
100: th.th_unique = addr;
101: if (callback (&th, cbdata_p) != 0)
102: return TD_DBERR;
103: }
104:
105:
106: err = DB_GET_FIELD_LOCAL (next, ta, copy + (ofs - (psaddr_t) 0), list_t,
107: next, 0);
108: if (err != TD_OK)
109: break;
110: }
111:
112: return err;
113: }
114:
115:
116: td_err_e
117: td_ta_thr_iter (const td_thragent_t *ta_arg, td_thr_iter_f *callback,
118: void *cbdata_p, td_thr_state_e state, int ti_pri,
119: sigset_t *ti_sigmask_p, unsigned int ti_user_flags)
120: {
121: td_thragent_t *const ta = (td_thragent_t *) ta_arg;
122: td_err_e err;
123: psaddr_t list = 0;
124:
125: LOG ("td_ta_thr_iter");
126:
127:
128: if (! ta_ok (ta))
129: return TD_BADTA;
130:
131:
132:
133:
134:
135:
136:
137:
138: err = DB_GET_SYMBOL (list, ta, __stack_user);
139: if (err == TD_OK)
140: err = iterate_thread_list (ta, callback, cbdata_p, state, ti_pri,
141: list, true);
142:
143:
144: if (err == TD_OK)
145: err = DB_GET_SYMBOL (list, ta, stack_used);
146: if (err == TD_OK)
147: err = iterate_thread_list (ta, callback, cbdata_p, state, ti_pri,
148: list, false);
149:
150: return err;
151: }