2
2
* OXT - OS eXtensions for boosT
3
3
* Provides important functionality necessary for writing robust server software.
4
4
*
5
- * Copyright (c) 2010 Phusion
5
+ * Copyright (c) 2010, 2011, 2012 Phusion
6
6
*
7
7
* Permission is hereby granted, free of charge, to any person obtaining a copy
8
8
* of this software and associated documentation files (the "Software"), to deal
27
27
28
28
#define OXT_BACKTRACE_IS_ENABLED
29
29
30
- #include < boost/thread/mutex.hpp>
31
30
#include < boost/current_function.hpp>
32
- #include < exception>
33
- #include < string>
34
- #include < list>
35
- #include < vector>
36
- #include " ../spin_lock.hpp"
37
- #include " ../macros.hpp"
38
31
39
32
namespace oxt {
40
33
41
- using namespace std ;
42
- using namespace boost ;
43
- struct trace_point ;
44
- class tracable_exception ;
45
- struct thread_registration ;
46
-
47
- extern boost::mutex _thread_registration_mutex;
48
- extern list<thread_registration *> _registered_threads;
49
-
50
- void _init_backtrace_tls ();
51
- void _finalize_backtrace_tls ();
52
- bool _get_backtrace_list_and_its_lock (vector<trace_point *> **backtrace_list, spin_lock **lock);
53
- string _format_backtrace (const list<trace_point *> *backtrace_list);
54
- string _format_backtrace (const vector<trace_point *> *backtrace_list);
55
-
56
34
/* *
57
35
* A single point in a backtrace. Creating this object will cause it
58
36
* to push itself to the thread's backtrace list. This backtrace list
@@ -61,96 +39,21 @@ string _format_backtrace(const vector<trace_point *> *backtrace_list);
61
39
* backtrace list.
62
40
*
63
41
* Except if you set the 'detached' argument to true.
64
- *
65
- * Implementation detail - do not use directly!
66
- * @internal
67
42
*/
68
43
struct trace_point {
69
44
const char *function;
70
45
const char *source;
71
46
unsigned int line;
72
47
bool m_detached;
73
48
74
- trace_point (const char *function, const char *source, unsigned int line) {
75
- this ->function = function;
76
- this ->source = source;
77
- this ->line = line;
78
- m_detached = false ;
79
-
80
- vector<trace_point *> *backtrace_list;
81
- spin_lock *lock;
82
- if (OXT_LIKELY (_get_backtrace_list_and_its_lock (&backtrace_list, &lock))) {
83
- spin_lock::scoped_lock l (*lock);
84
- backtrace_list->push_back (this );
85
- }
86
- }
87
-
88
- trace_point (const char *function, const char *source, unsigned int line, bool detached) {
89
- this ->function = function;
90
- this ->source = source;
91
- this ->line = line;
92
- m_detached = true ;
93
- }
94
-
95
- ~trace_point () {
96
- if (OXT_LIKELY (!m_detached)) {
97
- vector<trace_point *> *backtrace_list;
98
- spin_lock *lock;
99
- if (OXT_LIKELY (_get_backtrace_list_and_its_lock (&backtrace_list, &lock))) {
100
- spin_lock::scoped_lock l (*lock);
101
- backtrace_list->pop_back ();
102
- }
103
- }
104
- }
105
-
106
- void update (const char *source, unsigned int line) {
107
- this ->source = source;
108
- this ->line = line;
109
- }
49
+ trace_point (const char *function, const char *source, unsigned int line);
50
+ trace_point (const char *function, const char *source, unsigned int line, bool detached);
51
+ ~trace_point ();
52
+ void update (const char *source, unsigned int line);
110
53
};
111
54
112
55
#define TRACE_POINT () oxt::trace_point __p (BOOST_CURRENT_FUNCTION, __FILE__, __LINE__)
113
56
#define TRACE_POINT_WITH_NAME (name ) oxt::trace_point __p (name, __FILE__, __LINE__)
114
57
#define UPDATE_TRACE_POINT () __p.update(__FILE__, __LINE__)
115
58
116
- /* *
117
- * @internal
118
- */
119
- struct thread_registration {
120
- string name;
121
- spin_lock *backtrace_lock;
122
- vector<trace_point *> *backtrace;
123
- };
124
-
125
- /* *
126
- * @internal
127
- */
128
- struct initialize_backtrace_support_for_this_thread {
129
- thread_registration *registration;
130
- list<thread_registration *>::iterator it;
131
-
132
- initialize_backtrace_support_for_this_thread (const string &name) {
133
- _init_backtrace_tls ();
134
- registration = new thread_registration ();
135
- registration->name = name;
136
- _get_backtrace_list_and_its_lock (®istration->backtrace ,
137
- ®istration->backtrace_lock );
138
-
139
- boost::mutex::scoped_lock l (_thread_registration_mutex);
140
- _registered_threads.push_back (registration);
141
- it = _registered_threads.end ();
142
- it--;
143
- }
144
-
145
- ~initialize_backtrace_support_for_this_thread () {
146
- {
147
- boost::mutex::scoped_lock l (_thread_registration_mutex);
148
- _registered_threads.erase (it);
149
- delete registration;
150
- }
151
- _finalize_backtrace_tls ();
152
- }
153
- };
154
-
155
59
} // namespace oxt
156
-
0 commit comments