123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173 |
- #include "thread_dbP.h"
- #include <alloca.h>
- static int
- handle_descr (const td_thragent_t *ta, td_thr_iter_f *callback,
- void *cbdata_p, td_thr_state_e state, int ti_pri,
- size_t cnt, pthread_descr descr)
- {
- struct _pthread_descr_struct pds;
- size_t sizeof_descr = ta->sizeof_descr;
- td_thrhandle_t th;
- if (descr == NULL)
- {
-
- if (cnt == 0)
- {
-
- memset (&pds, '\0', sizeof (pds));
-
- pds.p_self = &pds;
- pds.p_nextlive = pds.p_prevlive = &pds;
- pds.p_tid = PTHREAD_THREADS_MAX;
-
- th.th_ta_p = (td_thragent_t *) ta;
- th.th_unique = NULL;
- if (callback (&th, cbdata_p) != 0)
- return TD_DBERR;
-
- return TD_OK;
- }
- else if (cnt == 1)
-
- return TD_OK;
- else
-
- return TD_ERR;
- }
- if (ps_pdread (ta->ph, descr, &pds, sizeof_descr) != PS_OK)
- return TD_ERR;
-
- if (cnt == 1 && pds.p_pid == 0)
- return TD_OK;
-
-
- if (pds.p_priority < ti_pri)
- return TD_OK;
-
- if (state != TD_THR_ANY_STATE)
- return TD_OK;
-
- if (pds.p_exited != 0)
- return TD_OK;
-
- th.th_ta_p = (td_thragent_t *) ta;
- th.th_unique = descr;
- if (callback (&th, cbdata_p) != 0)
- return TD_DBERR;
-
- return TD_OK;
- }
- td_err_e
- td_ta_thr_iter (const td_thragent_t *ta, 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)
- {
- int pthread_threads_max;
- struct pthread_handle_struct *phc;
- td_err_e result = TD_OK;
- int cnt;
- #ifdef ALL_THREADS_STOPPED
- int num;
- #else
- # define num 1
- #endif
- LOG ("td_ta_thr_iter");
-
- if (! ta_ok (ta))
- return TD_BADTA;
- pthread_threads_max = ta->pthread_threads_max;
- phc = (struct pthread_handle_struct *) alloca (sizeof (phc[0])
- * pthread_threads_max);
-
- if (ps_pdread (ta->ph, ta->handles, phc,
- sizeof (struct pthread_handle_struct) * 2) != PS_OK)
- return TD_ERR;
-
- result = handle_descr (ta, callback, cbdata_p, state, ti_pri, 0,
- phc[0].h_descr);
- if (result != TD_OK)
- return result;
- result = handle_descr (ta, callback, cbdata_p, state, ti_pri, 1,
- phc[1].h_descr);
- if (result != TD_OK)
- return result;
-
- if (ps_pdread (ta->ph, ta->handles + 2, &phc[2],
- (sizeof (struct pthread_handle_struct)
- * (pthread_threads_max - 2))) != PS_OK)
- return TD_ERR;
- #ifdef ALL_THREADS_STOPPED
-
- if (ps_pdread (ta->ph, ta->pthread_handles_num, &num, sizeof (int)) != PS_OK)
- return TD_ERR;
- #endif
-
- for (cnt = 2; cnt < pthread_threads_max && num > 0; ++cnt)
- if (phc[cnt].h_descr != NULL)
- {
- #ifdef ALL_THREADS_STOPPED
-
- --num;
- #endif
- result = handle_descr (ta, callback, cbdata_p, state, ti_pri, cnt,
- phc[cnt].h_descr);
- if (result != TD_OK)
- break;
- }
- return result;
- }
|