home *** CD-ROM | disk | FTP | other *** search
/ Tricks of the Windows Gam…ming Gurus (2nd Edition) / Disc2.iso / vc98 / crt / src / tidprint.c < prev    next >
C/C++ Source or Header  |  1998-06-17  |  4KB  |  136 lines

  1. /***
  2. *tidprint.c - Dislpay thread data
  3. *
  4. *       Copyright (c) 1988-1997, Microsoft Corporation. All rights reserved.
  5. *
  6. *Purpose:
  7. *       Display the per thread data table.
  8. *
  9. *       [NOTE: This module is NOT included in the C runtime libraries but
  10. *       is maintained for debugging analysis.]
  11. *
  12. *******************************************************************************/
  13.  
  14. #include <cruntime.h>
  15. #include <stdio.h>
  16. #include <mtdll.h>
  17.  
  18. void __cdecl _print_tiddata(unsigned long);
  19. void __cdecl _print_tiddata1(_ptiddata);
  20.  
  21. /***
  22. *void _print_tiddata(unsigned long) - Display data for a thread
  23. *
  24. *Purpose:
  25. *       This routine displays the per thread data for a specific, or all,
  26. *       active threads in the _ptd[] table.
  27. *
  28. *Entry:
  29. *       unsigned long = <n> = ID of the thread to display
  30. *                     = -1  = Display thread data for all threads
  31. *
  32. *Exit:
  33. *       <void>
  34. *
  35. *Exceptions:
  36. *
  37. *******************************************************************************/
  38.  
  39. void __cdecl _print_tiddata (
  40.         unsigned long tid
  41.         )
  42. {
  43.         int i;                  /* loop index */
  44.         int threadcnt;          /* number of active threads */
  45.  
  46.         /*
  47.          * lock the _ptd[] table.
  48.          */
  49.         _mlock(_THREADDATA_LOCK);
  50.  
  51.         /*
  52.          * see if caller want's all threads or just a specific one.
  53.          */
  54.         if (tid == (unsigned long) -1L) {
  55.                 /*
  56.                  * caller want's all threads!
  57.                  */
  58.                 for ( i = threadcnt = 0 ; i < 1024 ; i++ )
  59.                         /*
  60.                          * print out the fields of *_ptd[i] for each entry
  61.                          * bound to an active thread (i.e., for each i st
  62.                          * _ptd[i] non-NULL). also, count up the total number
  63.                          * of active threads.
  64.                          */
  65.                         if ( _ptd[i] != NULL ) {
  66.                                 threadcnt++;
  67.                                 _print_tiddata1(_ptd[i]);
  68.                         }
  69.  
  70.                 printf("\nTHERE ARE %d CURRENTLY ACTIVE THREADS!\n", threadcnt);
  71.         }
  72.         else {
  73.                 /*
  74.                  * caller just interested in a particular thread. search
  75.                  * the _ptd[] table inline because a call to _getptd[] would
  76.                  * have unpleasant side effects if tid is not (or no longer)
  77.                  * valid.
  78.                  */
  79.                 for ( i = 0 ; (i < 1024) && ((_ptd[i] == NULL) ||
  80.                     (_ptd[i] == (_ptiddata)1L) || (_ptd[i]->_tid != tid)) ;
  81.                     i++ ) ;
  82.  
  83.                 if ( i < 1024 )
  84.                         _print_tiddata1(_ptd[i]);
  85.                 else
  86.                         printf("\nTID INVALID OR THREAD HAS TERMINATED!\n");
  87.         }
  88.  
  89.         /*
  90.          * unlock the _ptd[] table.
  91.          */
  92.         _munlock(_THREADDATA_LOCK);
  93.  
  94. }
  95.  
  96.  
  97. /***
  98. * void _print_tiddata1(_ptiddata ptd) - print out _tiddata structure
  99. *
  100. *Purpose:
  101. *       Given a pointer to a thread data structure, print out its contents
  102. *
  103. *Entry:
  104. *       ptd = pointer to thread's data area
  105. *
  106. *Exit:
  107. *       <void>
  108. *
  109. *Exceptions:
  110. *
  111. *******************************************************************************/
  112.  
  113. void __cdecl _print_tiddata1 (
  114.         _ptiddata ptd
  115.         )
  116. {
  117.         printf("\t_tid            = %lu\n",  ptd->_tid );
  118.         printf("\t_thandle        = %lu\n",  ptd->_thandle );
  119.         printf("\t_terrno         = %d\n",   ptd->_terrno);
  120.         printf("\t_tdoserrno      = %d\n",   ptd->_tdoserrno);
  121.         printf("\t_fpds           = %#x\n",  ptd->_fpds);
  122.         printf("\t_holdrand       = %u\n",   ptd->_holdrand);
  123.         printf("\t_token          = %p\n",   ptd->_token);
  124.         printf("\t_errmsg         = %p\n",   ptd->_errmsg);
  125.         printf("\t_namebuf        = %p\n",   ptd->_namebuf);
  126.         printf("\t_asctimebuf     = %p\n",   ptd->_asctimebuf);
  127.         printf("\t_wasctimebuf    = %p\n",   ptd->_wasctimebuf);
  128.         printf("\t_gmtimebuf      = %p\n",   ptd->_gmtimebuf);
  129.         printf("\t_initaddr       = %p\n",   ptd->_initaddr);
  130.         printf("\t_initarg        = %p\n",   ptd->_initarg);
  131.         printf("\t_pxcptacttab    = %p\n",   ptd->_pxcptacttab);
  132.         printf("\t_tpxcptinfoptrs = %p\n",   ptd->_tpxcptinfoptrs);
  133.         printf("\t_tfpecode       = %p\n\n", ptd->_tfpecode);
  134.  
  135. }
  136.