Update.
[glibc.git] / linuxthreads_db / td_ta_thr_iter.c
blobe25230c2b418491e119ea946a35203f5d805d8f8
1 /* Iterate over a process's threads.
2 Copyright (C) 1999 Free Software Foundation, Inc.
3 This file is part of the GNU C Library.
4 Contributed by Ulrich Drepper <drepper@cygnus.com>, 1999.
6 The GNU C Library is free software; you can redistribute it and/or
7 modify it under the terms of the GNU Library General Public License as
8 published by the Free Software Foundation; either version 2 of the
9 License, or (at your option) any later version.
11 The GNU C Library is distributed in the hope that it will be useful,
12 but WITHOUT ANY WARRANTY; without even the implied warranty of
13 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
14 Library General Public License for more details.
16 You should have received a copy of the GNU Library General Public
17 License along with the GNU C Library; see the file COPYING.LIB. If not,
18 write to the Free Software Foundation, Inc., 59 Temple Place - Suite 330,
19 Boston, MA 02111-1307, USA. */
21 #include "thread_dbP.h"
24 td_err_e
25 td_ta_thr_iter (const td_thragent_t *ta, td_thr_iter_f *callback,
26 void *cbdata_p, td_thr_state_e state, int ti_pri,
27 sigset_t *ti_sigmask_p, unsigned int ti_user_flags)
29 struct pthread_handle_struct *handles = ta->handles;
30 int pthread_threads_max = ta->pthread_threads_max;
31 int cnt;
33 LOG (__FUNCTION__);
35 /* Now get all descriptors, one after the other. */
36 for (cnt = 0; cnt < pthread_threads_max; ++cnt, ++handles)
38 struct pthread_handle_struct phc;
40 if (ps_pdread (ta->ph, handles, &phc,
41 sizeof (struct pthread_handle_struct)) != PS_OK)
42 return TD_ERR; /* XXX Other error value? */
44 if (phc.h_descr != NULL)
46 struct _pthread_descr_struct pds;
47 td_thrhandle_t th;
49 if (ps_pdread (ta->ph, phc.h_descr, &pds,
50 sizeof (struct _pthread_descr_struct)) != PS_OK)
51 return TD_ERR; /* XXX Other error value? */
53 /* Now test whether this thread matches the specified
54 conditions. */
56 /* Only if the priority level is as high or higher. */
57 if (pds.p_priority < ti_pri)
58 continue;
60 /* Yep, it matches. Call the callback function. */
61 th.th_ta_p = (td_thragent_t *) ta;
62 th.th_unique = phc.h_descr;
63 if (callback (&th, cbdata_p) != 0)
64 return TD_DBERR;
68 return TD_OK;