* To help us fund GROMACS development, we humbly ask that you cite
* the research papers on the package. Check out http://www.gromacs.org.
*/
+#include "gmxpre.h"
+
#include "fatalerror.h"
-#ifdef HAVE_CONFIG_H
-#include <config.h>
-#endif
+#include "config.h"
#include <cerrno>
#include <cstdarg>
#include "gromacs/utility/programcontext.h"
#include "gromacs/utility/smalloc.h"
-static gmx_bool bDebug = FALSE;
-static FILE *log_file = NULL;
-
-static tMPI_Thread_mutex_t debug_mutex = TMPI_THREAD_MUTEX_INITIALIZER;
+static bool bDebug = false;
static tMPI_Thread_mutex_t where_mutex = TMPI_THREAD_MUTEX_INITIALIZER;
+FILE *debug = NULL;
+gmx_bool gmx_debug_at = FALSE;
+
+static FILE *log_file = NULL;
+static tMPI_Thread_mutex_t error_mutex = TMPI_THREAD_MUTEX_INITIALIZER;
static const char *const gmxuser
= "Please report this to the mailing list (gmx-users@gromacs.org)";
-gmx_bool bDebugMode(void)
+void gmx_init_debug(const int dbglevel, const char *dbgfile)
{
- return bDebug;
+ if (!bDebug)
+ {
+ gmx_disable_file_buffering();
+ debug = gmx_ffopen(dbgfile, "w+");
+ bDebug = true;
+ if (dbglevel >= 2)
+ {
+ gmx_debug_at = TRUE;
+ }
+ }
}
-void gmx_fatal_set_log_file(FILE *fp)
+gmx_bool bDebugMode(void)
{
- log_file = fp;
+ return bDebug;
}
void _where(const char *file, int line)
if (bFirst) /* we repeat the check in the locked section because things
might have changed */
{
- if ((temp = getenv("WHERE")) != NULL)
+ if ((temp = getenv("GMX_PRINT_DEBUG_LINES")) != NULL)
{
nskip = strtol(temp, NULL, 10);
}
}
}
+void gmx_fatal_set_log_file(FILE *fp)
+{
+ log_file = fp;
+}
+
static int fatal_errno = 0;
static void default_error_handler(const char *msg)
{
- tMPI_Thread_mutex_lock(&debug_mutex);
+ tMPI_Thread_mutex_lock(&error_mutex);
if (fatal_errno == 0)
{
if (log_file)
}
perror(msg);
}
- tMPI_Thread_mutex_unlock(&debug_mutex);
+ tMPI_Thread_mutex_unlock(&error_mutex);
}
static void (*gmx_error_handler)(const char *msg) = default_error_handler;
{
// TODO: Either this is unnecessary, or also reads to the handler should be
// protected by a mutex.
- tMPI_Thread_mutex_lock(&debug_mutex);
+ tMPI_Thread_mutex_lock(&error_mutex);
gmx_error_handler = func;
- tMPI_Thread_mutex_unlock(&debug_mutex);
+ tMPI_Thread_mutex_unlock(&error_mutex);
}
static void call_error_handler(const char *key, const char *file, int line, const char *msg)
gmx_error_handler(buf);
}
-GMX_ATTRIBUTE_NORETURN static void do_exit(bool bMaster, bool bFinalize)
+gmx_noreturn static void do_exit(bool bMaster, bool bFinalize)
{
if (debug)
{
char msg[STRLEN];
vsprintf(msg, fmt, ap);
- tMPI_Thread_mutex_lock(&debug_mutex);
+ tMPI_Thread_mutex_lock(&error_mutex);
fatal_errno = f_errno;
- tMPI_Thread_mutex_unlock(&debug_mutex);
+ tMPI_Thread_mutex_unlock(&error_mutex);
call_error_handler("fatal", file, line, msg);
}
va_end(ap);
}
-/*
- * These files are global variables in the gromacs preprocessor
- * Every routine in a file that includes gmx_fatal.h can write to these
- * debug channels. Depending on the debuglevel used
- * 0 to 3 of these filed are redirected to /dev/null
- *
- */
-FILE *debug = NULL;
-gmx_bool gmx_debug_at = FALSE;
-
-void init_debug(const int dbglevel, const char *dbgfile)
-{
- tMPI_Thread_mutex_lock(&debug_mutex);
- if (!bDebug) /* another thread hasn't already run this*/
- {
- no_buffers();
- debug = gmx_ffopen(dbgfile, "w+");
- bDebug = TRUE;
- if (dbglevel >= 2)
- {
- gmx_debug_at = TRUE;
- }
- }
- tMPI_Thread_mutex_unlock(&debug_mutex);
-}
-
char *gmx_strerror(const char *key)
{
typedef struct {