summaryrefslogtreecommitdiff
path: root/src/debug.cpp
diff options
context:
space:
mode:
authorkwolekr <kwolekr@minetest.net>2015-10-16 21:12:30 -0400
committerkwolekr <kwolekr@minetest.net>2015-10-16 22:20:24 -0400
commit6be74d17df75714066b36cfa6ae40081526ef477 (patch)
tree13bf9b742aff873d3e618a610973812c4545945c /src/debug.cpp
parent836486a98e7b09e25b97c9d989301ed9eb365b3b (diff)
downloadminetest-6be74d17df75714066b36cfa6ae40081526ef477.tar.gz
minetest-6be74d17df75714066b36cfa6ae40081526ef477.tar.bz2
minetest-6be74d17df75714066b36cfa6ae40081526ef477.zip
Refactor thread utility interface
- Add "thr_" prefix to thread utility functions - Compare threadid_ts in a portable manner, where possible
Diffstat (limited to 'src/debug.cpp')
-rw-r--r--src/debug.cpp13
1 files changed, 10 insertions, 3 deletions
diff --git a/src/debug.cpp b/src/debug.cpp
index 82aa6d519..9f1042646 100644
--- a/src/debug.cpp
+++ b/src/debug.cpp
@@ -45,7 +45,7 @@ void sanity_check_fn(const char *assertion, const char *file,
unsigned int line, const char *function)
{
errorstream << std::endl << "In thread " << std::hex
- << (unsigned long)get_current_thread_id() << ":" << std::endl;
+ << (unsigned long)thr_get_current_thread_id() << ":" << std::endl;
errorstream << file << ":" << line << ": " << function
<< ": An engine assumption '" << assertion << "' failed." << std::endl;
@@ -58,7 +58,7 @@ void fatal_error_fn(const char *msg, const char *file,
unsigned int line, const char *function)
{
errorstream << std::endl << "In thread " << std::hex
- << (unsigned long)get_current_thread_id() << ":" << std::endl;
+ << (unsigned long)thr_get_current_thread_id() << ":" << std::endl;
errorstream << file << ":" << line << ": " << function
<< ": A fatal error occured: " << msg << std::endl;
@@ -130,6 +130,13 @@ void DebugStack::print(std::ostream &os, bool everything)
os<<"Probably overflown."<<std::endl;
}
+// Note: Using pthread_t (that is, threadid_t on POSIX platforms) as the key to
+// a std::map is naughty. Formally, a pthread_t may only be compared using
+// pthread_equal() - pthread_t lacks the well-ordered property needed for
+// comparisons in binary searches. This should be fixed at some point by
+// defining a custom comparator with an arbitrary but stable ordering of
+// pthread_t, but it isn't too important since none of our supported platforms
+// implement pthread_t as a non-ordinal type.
std::map<threadid_t, DebugStack*> g_debug_stacks;
Mutex g_debug_stacks_mutex;
@@ -158,7 +165,7 @@ void debug_stacks_print()
DebugStacker::DebugStacker(const char *text)
{
- threadid_t threadid = get_current_thread_id();
+ threadid_t threadid = thr_get_current_thread_id();
MutexAutoLock lock(g_debug_stacks_mutex);