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

private_thread.h
Go to the documentation of this file.
1 // $Header$
2 //
3 // Copyright (C) 2002 - 2004, by
4 //
5 // Carlo Wood, Run on IRC <carlo@alinoe.com>
6 // RSA-1024 0x624ACAD5 1997-01-26 Sign & Encrypt
7 // Fingerprint16 = 32 EC A7 B6 AC DB 65 A6 F6 F6 55 DD 1C DC FF 61
8 //
9 // This file may be distributed under the terms of the Q Public License
10 // version 1.0 as appearing in the file LICENSE.QPL included in the
11 // packaging of this file.
12 //
13 
18 #ifndef LIBCWD_PRIVATE_THREAD_H
19 #define LIBCWD_PRIVATE_THREAD_H
20 
21 #ifndef LIBCWD_PRIVATE_MUTEX_H
22 #include <libcwd/private_mutex.h>
23 #endif
24 #ifndef LIBCWD_PRIVATE_ALLOCATOR_H
26 #endif
27 #ifndef LIBCW_LIST
28 #define LIBCW_LIST
29 #include <list>
30 #endif
31 
32 namespace libcwd {
33 
34 class dm_alloc_ct;
35 
36  namespace _private_ {
37 
38 struct TSD_st;
39 
40 // class thread_ct
41 //
42 // Each created thread gets an object of type `thread_ct' assigned.
43 // The objects are stored in an STL list so that we can use pointers
44 // to the objects without the fear that these pointers become invalid.
45 //
46 
47 class thread_ct {
48 
49 public:
50 #if CWDEBUG_ALLOC
51 typedef std::list<thread_ct, internal_allocator::rebind<thread_ct>::other> threadlist_type;
52 #else
53 typedef std::list<thread_ct> threadlist_type;
54 #endif
55 
56 public:
57  mutex_ct thread_mutex; // Mutex for the attributes of this object.
58 #if CWDEBUG_ALLOC
59  void* memblk_map; // Pointer to memblk_map_ct of this thread.
60  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.
61  dm_alloc_ct** current_alloc_list; // The current list to which newly allocated memory blocks are added.
62  dm_alloc_ct* current_owner_node; // If the current_alloc_list != &base_alloc_list, then this variable
63  // points to the dm_alloc_ct node who owns the current list.
64  size_t memsize; // Total number of allocated bytes (excluding internal allocations).
65  unsigned long memblks; // Total number of allocated blocks (excluding internal allocations).
66 #endif
67  pthread_t tid; // Thread ID. This is only used to print the ID list_allocations_on, and to
68  // terminate all threads in a DoutFatal(dc::fatal, ...).
69  bool M_zombie;
70  bool M_terminating;
71 
72  void initialize(LIBCWD_TSD_PARAM); // May only be called after the object reached its final place in memory.
73  void terminated(threadlist_type::iterator LIBCWD_COMMA_TSD_PARAM);
74  bool is_zombie(void) const { return M_zombie; }
75  void terminating(void) { M_terminating = true; }
76  bool is_terminating(void) const { return M_terminating; }
77 };
78 
79 // The list of threads.
80 // New thread objects are added in TSD_st::S_initialize.
81 typedef thread_ct::threadlist_type threadlist_t;
82 extern threadlist_t* threadlist;
83 
84  } // namespace _private_
85 } // namespace libcwd
86 
87 #endif // LIBCWD_PRIVATE_THREAD_H
88 
Copyright © 2001 - 2004 Carlo Wood.  All rights reserved.