-class MLocker {
- static Mutex the_lock;
-public:
- MLocker() { the_lock.lock(); }
- ~MLocker() { the_lock.unlock(); }
-};
-Mutex MLocker::the_lock;
-
-class the_dbg {
-public:
- pthread_t tid, owner; const char *name;
- the_dbg(pthread_t t, pthread_t o, const char *nm) { tid = t; owner = o; name = nm; }
- ~the_dbg() {}
-};
-
-
-static class the_list : public ArrayList<the_dbg*> {
-public:
- static void dump_threads(FILE *fp);
- the_list() {}
- ~the_list() {
- MLocker mlkr;
- remove_all_objects();
- }
-} thread_list;
-
-static void dbg_add(pthread_t tid, pthread_t owner, const char *nm)
-{
- MLocker mlkr;
- int i = thread_list.size();
- while( --i >= 0 && thread_list[i]->tid != tid );
- if( i >= 0 ) {
- printf("dbg_add, dup %016lx %s %s\n",
- (unsigned long)tid, nm, thread_list[i]->name);
- return;
- }
- thread_list.append(new the_dbg(tid, owner, nm));
-}
-
-static void dbg_del(pthread_t tid)
-{
- MLocker mlkr;
- int i = thread_list.size();
- while( --i >= 0 && thread_list[i]->tid != tid );
- if( i < 0 ) {
- printf("dbg_del, mis %016lx\n",(unsigned long)tid);
- return;
- }
- thread_list.remove_object_number(i);
-}
-
-static class the_chkr {
-public:
- the_chkr() {}
- ~the_chkr() {
- int i = thread_list.size();
- if( !i ) return;
- printf("unjoined tids / owner %d\n", i);
- while( --i >= 0 ) printf(" %016lx / %016lx %s\n",
- (unsigned long)thread_list[i]->tid,
- (unsigned long)thread_list[i]->owner,
- thread_list[i]->name);
- }
-} the_chk;
-#else
-#define dbg_add(t, nm) do {} while(0)
-#define dbg_del(t) do {} while(0)
-#endif