libcwd: The C++ Debugging Support Library - Reference Manual
Author: Carlo Wood
Description: C++ debugging support library with ostream debug output
Keywords: libcwd, debug output, debug facility, debug channel, object orientation, OO, C++, nested debug output, ostream, memory allocation, debugging, source file and line number

Main Page Reference Manual Namespace List Compound List Namespace Members Compound Members File Members

# libcwd/private_thread.h

Go to the documentation of this file.

    00001 // $Header$
    00002 //
    00003 // Copyright (C) 2002 - 2004, by
    00004 //
    00005 // Carlo Wood, Run on IRC <carlo@alinoe.com>
    00006 // RSA-1024 0x624ACAD5 1997-01-26                    Sign & Encrypt
    00007 // Fingerprint16 = 32 EC A7 B6 AC DB 65 A6  F6 F6 55 DD 1C DC FF 61
    00008 //
    00009 // This file may be distributed under the terms of the Q Public License
    00010 // version 1.0 as appearing in the file LICENSE.QPL included in the
    00011 // packaging of this file.
    00012 //
    00013
    00018 #ifndef LIBCWD_PRIVATE_THREAD_H
    00019 #define LIBCWD_PRIVATE_THREAD_H
    00020
    00021 #ifndef LIBCWD_PRIVATE_MUTEX_H
    00022 #include <libcwd/private_mutex.h>
    00023 #endif
    00024 #ifndef LIBCWD_PRIVATE_ALLOCATOR_H
    00025 #include <libcwd/private_allocator.h>
    00026 #endif
    00027 #ifndef LIBCW_LIST
    00028 #define LIBCW_LIST
    00029 #include <list>
    00030 #endif
    00031
    00032 namespace libcwd {
    00033
    00034 class dm_alloc_ct;
    00035
    00036   namespace _private_ {
    00037
    00038 struct TSD_st;
    00039
    00040 // class thread_ct
    00041 //
    00042 // Each created thread gets an object of type `thread_ct' assigned.
    00043 // The objects are stored in an STL list so that we can use pointers
    00044 // to the objects without the fear that these pointers become invalid.
    00045 //
    00046
    00047 class thread_ct {
    00048
    00049 public:
    00050 #if CWDEBUG_ALLOC
    00051 typedef std::list<thread_ct, internal_allocator::rebind<thread_ct>::other> threadlist_type;
    00052 #else
    00053 typedef std::list<thread_ct> threadlist_type;
    00054 #endif
    00055
    00056 public:
    00057   mutex_ct thread_mutex;                // Mutex for the attributes of this object.
    00058 #if CWDEBUG_ALLOC
    00059   void* memblk_map;                     // Pointer to memblk_map_ct of this thread.
    00060   dm_alloc_ct* base_alloc_list;         // The base list with `dm_alloc_ct' objects.  Each of these objects has a list of it's own.
    00061   dm_alloc_ct** current_alloc_list;     // The current list to which newly allocated memory blocks are added.
    00062   dm_alloc_ct* current_owner_node;      // If the current_alloc_list != &base_alloc_list, then this variable
    00063                                         // points to the dm_alloc_ct node who owns the current list.
    00064   size_t memsize;                       // Total number of allocated bytes (excluding internal allocations).
    00065   unsigned long memblks;                // Total number of allocated blocks (excluding internal allocations).
    00066 #endif
    00067   pthread_t tid;                        // Thread ID.  This is only used to print the ID list_allocations_on, and to
    00068                                         // terminate all threads in a DoutFatal(dc::fatal, ...).
    00069   bool M_zombie;
    00070   bool M_terminating;
    00071
    00072   void initialize(LIBCWD_TSD_PARAM);    // May only be called after the object reached its final place in memory.
    00073   void terminated(threadlist_type::iterator LIBCWD_COMMA_TSD_PARAM);
    00074   bool is_zombie(void) const { return M_zombie; }
    00075   void terminating(void) { M_terminating = true; }
    00076   bool is_terminating(void) const { return M_terminating; }
    00077 };
    00078
    00079 // The list of threads.
    00080 // New thread objects are added in TSD_st::S_initialize.
    00081 typedef thread_ct::threadlist_type threadlist_t;
    00082 extern threadlist_t* threadlist;
    00083
    00084   } // namespace _private_
    00085 } // namespace libcwd
    00086
    00087 #endif // LIBCWD_PRIVATE_THREAD_H
    00088