22 * OXT - OS eXtensions for boosT
33 * Provides important functionality necessary for writing robust server software.
44 *
5- * Copyright (c) 2010 Phusion
5+ * Copyright (c) 2010, 2011, 2012 Phusion
66 *
77 * Permission is hereby granted, free of charge, to any person obtaining a copy
88 * of this software and associated documentation files (the "Software"), to deal
2727
2828#define OXT_BACKTRACE_IS_ENABLED
2929
30- #include < boost/thread/mutex.hpp>
3130#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"
3831
3932namespace oxt {
4033
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-
5634/* *
5735 * A single point in a backtrace. Creating this object will cause it
5836 * 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);
6139 * backtrace list.
6240 *
6341 * Except if you set the 'detached' argument to true.
64- *
65- * Implementation detail - do not use directly!
66- * @internal
6742 */
6843struct trace_point {
6944 const char *function;
7045 const char *source;
7146 unsigned int line;
7247 bool m_detached;
7348
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);
11053};
11154
11255#define TRACE_POINT () oxt::trace_point __p (BOOST_CURRENT_FUNCTION, __FILE__, __LINE__)
11356#define TRACE_POINT_WITH_NAME (name ) oxt::trace_point __p (name, __FILE__, __LINE__)
11457#define UPDATE_TRACE_POINT () __p.update(__FILE__, __LINE__)
11558
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-
15559} // namespace oxt
156-
0 commit comments