summaryrefslogtreecommitdiffstats
path: root/crawl-ref/source/crash.cc
diff options
context:
space:
mode:
authorAdam Borowski <kilobyte@angband.pl>2011-12-27 00:38:12 +0100
committerAdam Borowski <kilobyte@angband.pl>2011-12-27 14:54:20 +0100
commit0e9f143427c81ed407f51b85597ccb6f84319a18 (patch)
treee929745a27d265f27466f2d84b313c56f739bd66 /crawl-ref/source/crash.cc
parentfcc243cf405624cf8253b4b49b2a2ac1cf2026d4 (diff)
downloadcrawl-ref-0e9f143427c81ed407f51b85597ccb6f84319a18.tar.gz
crawl-ref-0e9f143427c81ed407f51b85597ccb6f84319a18.zip
Threading support.
Since Windows doesn't support pthreads without an external library, I used a mess of #defines. Also, some of the #defines are not needed; I copied them from an earlier project. Detached threads and cond variables are not used at the moment, if you feel bad about dormant code we can axe them.
Diffstat (limited to 'crawl-ref/source/crash.cc')
-rw-r--r--crawl-ref/source/crash.cc22
1 files changed, 21 insertions, 1 deletions
diff --git a/crawl-ref/source/crash.cc b/crawl-ref/source/crash.cc
index b9823ae27f..9fddfeffbe 100644
--- a/crawl-ref/source/crash.cc
+++ b/crawl-ref/source/crash.cc
@@ -62,10 +62,11 @@ template <typename TO, typename FROM> TO nasty_cast(FROM f)
#include "externs.h"
#include "files.h"
+#include "initfile.h"
#include "options.h"
#include "state.h"
#include "stuff.h"
-#include "initfile.h"
+#include "threads.h"
/////////////////////////////////////////////////////////////////////////////
// Code for printing out debugging info on a crash.
@@ -73,9 +74,18 @@ template <typename TO, typename FROM> TO nasty_cast(FROM f)
#ifdef USE_UNIX_SIGNALS
static int _crash_signal = 0;
static int _recursion_depth = 0;
+static mutex_t crash_mutex;
static void _crash_signal_handler(int sig_num)
{
+ // We rely on mutexes ignoring locks held by the same process, on some
+ // platforms this must be explicitely enabled (and we do so).
+
+ // This mutex is never unlocked again -- the first thread to crash will
+ // do a dump then terminate the process while everyone else waits here
+ // forever.
+ mutex_lock(crash_mutex);
+
if (crawl_state.game_crashed)
{
if (_recursion_depth > 0)
@@ -143,6 +153,8 @@ static void _crash_signal_handler(int sig_num)
void init_crash_handler()
{
+ mutex_init(crash_mutex);
+
#if defined(USE_UNIX_SIGNALS)
for (int i = 1; i <= 64; i++)
@@ -316,3 +328,11 @@ void write_stack_trace(FILE* file, int ignore_count)
fprintf(file, "%s", msg);
}
#endif
+
+void disable_other_crashes()
+{
+ // If one thread calls end() without going through a crash (a handled
+ // fatal error), no one else should be allowed to crash. We're already
+ // going down so blocking the other thread is ok.
+ mutex_lock(crash_mutex);
+}