123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151 |
- #include "thread_dbP.h"
- static td_err_e
- iterate_thread_list (td_thragent_t *ta, td_thr_iter_f *callback,
- void *cbdata_p, td_thr_state_e state, int ti_pri,
- psaddr_t head, bool fake_empty)
- {
- td_err_e err;
- psaddr_t next, ofs;
- void *copy;
- int descr_pri;
-
- if (state != TD_THR_ANY_STATE)
- return TD_OK;
- err = DB_GET_FIELD (next, ta, head, list_t, next, 0);
- if (err != TD_OK)
- return err;
- if (next == 0 && fake_empty)
- {
-
- td_thrhandle_t th = { ta, 0 };
- return callback (&th, cbdata_p) != 0 ? TD_DBERR : TD_OK;
- }
-
- err = DB_GET_FIELD_ADDRESS (ofs, ta, 0, pthread, list, 0);
- if (err != TD_OK)
- return err;
- if (ta->ta_sizeof_pthread == 0)
- {
- err = _td_check_sizeof (ta, &ta->ta_sizeof_pthread, SYM_SIZEOF_pthread);
- if (err != TD_OK)
- return err;
- }
- copy = __alloca (ta->ta_sizeof_pthread);
- while (next != head)
- {
- psaddr_t addr, schedpolicy, schedprio;
- addr = next - (ofs - (psaddr_t) 0);
- if (next == 0 || addr == 0)
- return TD_DBERR;
-
- if (ps_pdread (ta->ph, addr, copy, ta->ta_sizeof_pthread) != PS_OK)
- return TD_ERR;
- err = DB_GET_FIELD_LOCAL (schedpolicy, ta, copy, pthread,
- schedpolicy, 0);
- if (err != TD_OK)
- break;
- err = DB_GET_FIELD_LOCAL (schedprio, ta, copy, pthread,
- schedparam_sched_priority, 0);
- if (err != TD_OK)
- break;
-
-
- descr_pri = ((uintptr_t) schedpolicy == SCHED_OTHER
- ? 0 : (uintptr_t) schedprio);
- if (descr_pri >= ti_pri)
- {
-
- td_thrhandle_t th;
- th.th_ta_p = (td_thragent_t *) ta;
- th.th_unique = addr;
- if (callback (&th, cbdata_p) != 0)
- return TD_DBERR;
- }
-
- err = DB_GET_FIELD_LOCAL (next, ta, copy + (ofs - (psaddr_t) 0), list_t,
- next, 0);
- if (err != TD_OK)
- break;
- }
- return err;
- }
- td_err_e
- td_ta_thr_iter (const td_thragent_t *ta_arg, td_thr_iter_f *callback,
- void *cbdata_p, td_thr_state_e state, int ti_pri,
- sigset_t *ti_sigmask_p, unsigned int ti_user_flags)
- {
- td_thragent_t *const ta = (td_thragent_t *) ta_arg;
- td_err_e err;
- psaddr_t list = 0;
- LOG ("td_ta_thr_iter");
-
- if (! ta_ok (ta))
- return TD_BADTA;
-
- err = DB_GET_SYMBOL (list, ta, __stack_user);
- if (err == TD_OK)
- err = iterate_thread_list (ta, callback, cbdata_p, state, ti_pri,
- list, true);
-
- if (err == TD_OK)
- err = DB_GET_SYMBOL (list, ta, stack_used);
- if (err == TD_OK)
- err = iterate_thread_list (ta, callback, cbdata_p, state, ti_pri,
- list, false);
- return err;
- }
|