home *** CD-ROM | disk | FTP | other *** search
/ Linux Cubed Series 3: Developer Tools / Linux Cubed Series 3 - Developer Tools.iso / devel / lang / c / pthd-0.000 / pthd-0 / pthd-0.7 / src_tgrep / src-match / debug.h < prev    next >
Encoding:
C/C++ Source or Header  |  1995-08-15  |  1.8 KB  |  72 lines

  1.  
  2. #include <stdio.h>
  3. #ifdef PTHREADS_ACTIVE
  4. #include <pthread.h>
  5. /* #include <sched.h> @@ */
  6. #else
  7. #include <thread.h>
  8. #include <synch.h>
  9. #endif
  10. #ifdef __sparc
  11. #include <note.h> /* warlock/locklint */
  12. #else
  13. #define NOTE(s) 
  14. #endif
  15.  
  16.  
  17. #define DLEVEL1    0x0001    /* 1 */
  18. #define DLEVEL2    0x0002    /* 2 */
  19. #define DLEVEL3    0x0004    /* 4 */
  20. #define DLEVEL4    0x0008    /* 8 */
  21. #define DLEVEL5    0x0010    /* 16 */
  22. #define DLEVEL6    0x0020  /* 32 */
  23. #define DLEVEL7    0x0040    /* 64 */
  24. #define DLEVEL8    0x0080  /* 128 */
  25. #define DLEVEL9 0xFFFF  /* ALL */
  26. #define DLEVELA 0xFFFF  /* ALL */
  27.  
  28. #ifdef DEBUG
  29. typedef struct debug_set_st {
  30.     char level;
  31.     int  flag;
  32.     char *name;
  33. } debug_set_t;
  34.  
  35. debug_set_t debug_set[9] = { {'1', DLEVEL1, "Main Thread"}, 
  36.                  {'2', DLEVEL2, "File Limit"},
  37.                  {'3', DLEVEL3, "Cascade Thread"},
  38.                  {'4', DLEVEL4, "N/A"},
  39.                  {'5', DLEVEL5, "Search Thread"},
  40.                  {'6', DLEVEL6, "Glue functions"}, 
  41.                  {'7', DLEVEL7, "Signals"},
  42.                  {'8', DLEVEL8, "N/A"},
  43.                  {'9', DLEVEL9, "All Levels"}
  44.                            };
  45.  
  46. int debug_levels = 0x0000;
  47.  
  48. #define MAXDEBUG 10
  49. #ifdef PTHREADS_ACTIVE
  50. pthread_mutex_t debug_lock;
  51.  
  52. #define DP(level, string)  pthread_mutex_lock(&debug_lock); \
  53.                            if (debug_levels & level) { \
  54.                               printf("Thr %p: ", pthread_self()); \
  55.                   printf string ; \
  56.                } \
  57.                            pthread_mutex_unlock(&debug_lock);
  58. #else
  59. mutex_t debug_lock;
  60.  
  61. #define DP(level, string)  mutex_lock(&debug_lock); \
  62.                            if (debug_levels & level) { \
  63.                               printf("Thr %d: ", thr_self()); \
  64.                   printf string ; \
  65.                } \
  66.                            mutex_unlock(&debug_lock);
  67. #endif /* PTHREADS_ACTIVE */
  68. #else
  69. #define DP(level, string)
  70. #endif
  71. NOTE(MUTEX_PROTECTS_DATA(debug_lock, debug_set debug_levels))
  72.