Back to index

glibc  2.9
td_thr_get_info.c
Go to the documentation of this file.
00001 /* Get thread information.
00002    Copyright (C) 1999, 2000, 2001, 2002 Free Software Foundation, Inc.
00003    This file is part of the GNU C Library.
00004    Contributed by Ulrich Drepper <drepper@cygnus.com>, 1999.
00005 
00006    The GNU C Library is free software; you can redistribute it and/or
00007    modify it under the terms of the GNU Lesser General Public
00008    License as published by the Free Software Foundation; either
00009    version 2.1 of the License, or (at your option) any later version.
00010 
00011    The GNU C Library is distributed in the hope that it will be useful,
00012    but WITHOUT ANY WARRANTY; without even the implied warranty of
00013    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
00014    Lesser General Public License for more details.
00015 
00016    You should have received a copy of the GNU Lesser General Public
00017    License along with the GNU C Library; if not, write to the Free
00018    Software Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA
00019    02111-1307 USA.  */
00020 
00021 #include <stddef.h>
00022 #include <string.h>
00023 
00024 #include "thread_dbP.h"
00025 
00026 
00027 td_err_e
00028 td_thr_get_info (const td_thrhandle_t *th, td_thrinfo_t *infop)
00029 {
00030   struct _pthread_descr_struct pds;
00031 
00032   LOG ("td_thr_get_info");
00033 
00034   /* Handle the case when the thread library is not yet initialized.  */
00035   if (th->th_unique == NULL)
00036     {
00037       memset (&pds, '\0', sizeof (pds));
00038       pds.p_tid = PTHREAD_THREADS_MAX;
00039     }
00040   else
00041     /* Get the thread descriptor.  */
00042     if (ps_pdread (th->th_ta_p->ph, th->th_unique, &pds,
00043                  th->th_ta_p->sizeof_descr) != PS_OK)
00044       return TD_ERR; /* XXX Other error value?  */
00045 
00046   /* Fill in information.  Clear first to provide reproducable
00047      results for the fields we do not fill in.  */
00048   memset (infop, '\0', sizeof (td_thrinfo_t));
00049 
00050   /* We have to handle the manager thread special since the thread
00051      descriptor in older versions is not fully initialized.  */
00052   if (pds.p_nr == 1)
00053     {
00054       infop->ti_tid = th->th_ta_p->pthread_threads_max * 2 + 1;
00055       infop->ti_type = TD_THR_SYSTEM;
00056       infop->ti_state = TD_THR_ACTIVE;
00057     }
00058   else
00059     {
00060       infop->ti_tid = pds.p_tid;
00061       infop->ti_tls = (char *) pds.p_specific;
00062       infop->ti_pri = pds.p_priority;
00063       infop->ti_type = TD_THR_USER;
00064 
00065       if (! pds.p_terminated)
00066        /* XXX For now there is no way to get more information.  */
00067        infop->ti_state = TD_THR_ACTIVE;
00068       else if (! pds.p_detached)
00069        infop->ti_state = TD_THR_ZOMBIE;
00070       else
00071        infop->ti_state = TD_THR_UNKNOWN;
00072     }
00073 
00074   /* Initialization which are the same in both cases.  */
00075   infop->ti_lid = pds.p_pid ?: ps_getpid (th->th_ta_p->ph);
00076   infop->ti_ta_p = th->th_ta_p;
00077   infop->ti_startfunc = pds.p_start_args.start_routine;
00078   memcpy (&infop->ti_events, &pds.p_eventbuf.eventmask,
00079          sizeof (td_thr_events_t));
00080   infop->ti_traceme = pds.p_report_events != 0;
00081 
00082   return TD_OK;
00083 }