LAL  7.5.0.1-08ee4f4
LALGSL.c
Go to the documentation of this file.
1 /*
2 * Copyright (C) 2007 Jolien Creighton
3 *
4 * This program is free software; you can redistribute it and/or modify
5 * it under the terms of the GNU General Public License as published by
6 * the Free Software Foundation; either version 2 of the License, or
7 * (at your option) any later version.
8 *
9 * This program is distributed in the hope that it will be useful,
10 * but WITHOUT ANY WARRANTY; without even the implied warranty of
11 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12 * GNU General Public License for more details.
13 *
14 * You should have received a copy of the GNU General Public License
15 * along with with program; see the file COPYING. If not, write to the
16 * Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston,
17 * MA 02110-1301 USA
18 */
19 
20 #include <lal/LALStdlib.h>
21 #include <lal/LALGSL.h>
22 #include <gsl/gsl_errno.h>
23 
25 #ifdef LAL_PTHREAD_LOCK
26 #include <pthread.h>
27 pthread_mutex_t lalGSLPthreadMutex = PTHREAD_MUTEX_INITIALIZER;
28 #endif
29 
30 #if __GNUC__
31 #define UNUSED __attribute__ ((unused))
32 #else
33 #define UNUSED
34 #endif
35 
36 /**
37  * \ingroup LALGSL_h
38  * \brief LAL GSL error handler.
39  *
40  * ### Synopsis ###
41  *
42  * \code
43  * extern LALStatus *lalGSLGlobalStatusPtr;
44  * #include <lal/LALConfig.h>
45  * #ifdef LAL_PTHREAD_LOCK
46  * #include <pthread.h>
47  * extern pthread_mutex_t lalGSLPthreadMutex;
48  * #endif
49  * \endcode
50  *
51  * ### Description ###
52  *
53  * The function \c LALGSLErrorHandler() is the standard GSL error handler
54  * for GSL functions called within LAL. Its function is to take the GSL
55  * error code and information and translate them into equivalent aspects of
56  * the LAL status structure. The status structure that is currently identified
57  * by \c lalGSLGlobalStatusPtr is populated. This global variable is to
58  * be set to the current status pointer prior to invocation of the GSL function.
59  * In addition, the GSL error handler must be set to the LAL GSL error handler
60  * prior to the invocation of the GSL function. Both of these tasks can be
61  * done with the macros provided in the header \ref LALGSL_h.
62  * However, doing so is not thread-safe. Thus the macros use the mutex
63  * \c lalGSLPthreadMutex to block other threads from making GSL calls
64  * <em>from within LAL functions</em> while one thread has set the GSL error
65  * handler and global status pointer. This mutex must also be used to block
66  * any non-LAL GSL function calls from other threads or else they may be called
67  * with the LAL GSL error handler in effect.
68  */
69 void
70 LALGSLErrorHandler(UNUSED const char *reason,
71  const char *file, int line, int my_gsl_error)
72 {
73  if (!lalGSLGlobalStatusPtr) {
75  ("Abort: function LALGSLErrorHandler, file %s, line %d, %s\n"
76  " Null global status pointer\n", __FILE__, __LINE__,
77  "$Id$");
78  }
81  lalGSLGlobalStatusPtr->statusDescription = gsl_strerror(my_gsl_error);
82  lalGSLGlobalStatusPtr->statusCode = my_gsl_error;
87  return;
88 }
void(* lalAbortHook)(const char *,...)
Definition: LALError.c:75
#define LALError(statusptr, statement)
Definition: LALError.h:95
#define LALTrace(statusptr, exitflg)
Definition: LALError.h:117
LALStatus * lalGSLGlobalStatusPtr
Definition: LALGSL.c:24
#define INITSTATUS(statusptr)
void LALGSLErrorHandler(UNUSED const char *reason, const char *file, int line, int my_gsl_error)
LAL GSL error handler.
Definition: LALGSL.c:70
LAL status structure, see The LALStatus structure for more details.
Definition: LALDatatypes.h:947
const CHAR * file
The name of the source file containing the function code.
Definition: LALDatatypes.h:952
INT4 statusCode
A numerical code identifying the type of error, or 0 for nominal status; Negative values are reserved...
Definition: LALDatatypes.h:948
const CHAR * statusDescription
An explanatory string corresponding to the numerical status code.
Definition: LALDatatypes.h:949
struct tagLALStatus * statusPtr
Pointer to the next node in the list; NULL if this function is not reporting a subroutine error.
Definition: LALDatatypes.h:954
INT4 line
The line number in the source file where the current statusCode was set.
Definition: LALDatatypes.h:953