LALGSL.c

Go to the documentation of this file.
00001 /*
00002 *  Copyright (C) 2007 Jolien Creighton
00003 *
00004 *  This program is free software; you can redistribute it and/or modify
00005 *  it under the terms of the GNU General Public License as published by
00006 *  the Free Software Foundation; either version 2 of the License, or
00007 *  (at your option) any later version.
00008 *
00009 *  This program is distributed in the hope that it will be useful,
00010 *  but WITHOUT ANY WARRANTY; without even the implied warranty of
00011 *  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
00012 *  GNU General Public License for more details.
00013 *
00014 *  You should have received a copy of the GNU General Public License
00015 *  along with with program; see the file COPYING. If not, write to the
00016 *  Free Software Foundation, Inc., 59 Temple Place, Suite 330, Boston,
00017 *  MA  02111-1307  USA
00018 */
00019 
00020 /**** <lalVerbatim file="LALGSLCV">
00021  * Author: Creighton, J. D. E.
00022  * $Id: LALGSL.c,v 1.3 2007/06/08 14:41:53 bema Exp $
00023  **** </lalVerbatim> */
00024 
00025 /* <lalLaTeX>
00026 \subsection{Module \texttt{LALGSL.c}}
00027 
00028 LAL GSL error handler.
00029 
00030 \subsection*{Prototypes}
00031 \begin{verbatim}
00032 extern LALStatus *lalGSLGlobalStatusPtr;
00033 #include <lal/LALConfig.h>
00034 #ifdef LAL_PTHREAD_LOCK
00035 #include <pthread.h>
00036 extern pthread_mutex_t lalGSLPthreadMutex;
00037 #endif
00038 \end{verbatim}
00039 \input{LALGSLCP}
00040 \idx[Variable]{lalGSLGlobalStatusPtr}
00041 \idx[Variable]{lalGSLPthreadMutex}
00042 \idx{LALGSLErrorHandler}
00043 
00044 \subsection*{Description}
00045 
00046 The function \verb+LALGSLErrorHandler+ is the standard GSL error handler
00047 for GSL functions called within LAL.  Its function is to take the GSL
00048 error code and information and translate them into equivalent aspects of
00049 the LAL status structure.  The status structure that is currently identified
00050 by \verb+lalGSLGlobalStatusPtr+ is populated.  This global variable is to
00051 be set to the current status pointer prior to invocation of the GSL function.
00052 In addition, the GSL error handler must be set to the LAL GSL error handler
00053 prior to the invocation of the GSL function.  Both of these tasks can be
00054 done with the macros provided in the header \texttt{LALGSL.h} \ref{s:LALGSL.h}.
00055 However, doing so is not thread-safe.  Thus the macros use the mutex
00056 \verb+lalGSLPthreadMutex+ to block other threads from making GSL calls
00057 \emph{from within LAL functions} while one thread has set the GSL error
00058 handler and global status pointer.  This mutex must also be used to block
00059 any non-LAL GSL function calls from other threads or else they may be called
00060 with the LAL GSL error handler in effect.
00061 
00062 \vfill{\footnotesize\input{LALGSLCV}}
00063 </lalLaTeX> */
00064 
00065 #include <lal/LALStdlib.h>
00066 #include <lal/LALGSL.h>
00067 #include <gsl/gsl_errno.h>
00068 
00069 NRCSID( LALGSLC, "$Id: LALGSL.c,v 1.3 2007/06/08 14:41:53 bema Exp $" );
00070 
00071 LALStatus * lalGSLGlobalStatusPtr = NULL;
00072 #ifdef LAL_PTHREAD_LOCK
00073 #include <pthread.h>
00074 pthread_mutex_t lalGSLPthreadMutex = PTHREAD_MUTEX_INITIALIZER;
00075 #endif
00076 
00077 /* <lalVerbatim file="LALGSLCP"> */
00078 void
00079 LALGSLErrorHandler(
00080     const char *reason,
00081     const char *file,
00082     int line,
00083     int my_gsl_error
00084     )
00085 { /* </lalVerbatim> */
00086   if ( ! lalGSLGlobalStatusPtr )
00087   {
00088     lalAbortHook( "Abort: function LALGSLErrorHandler, file %s, line %d, %s\n"
00089                   "       Null global status pointer\n",
00090                   __FILE__, __LINE__, LALGSLC ); 
00091   }
00092   lalGSLGlobalStatusPtr->statusPtr = NULL;
00093   INITSTATUS( lalGSLGlobalStatusPtr, "LALGSLErrorHandler", LALGSLC );
00094   lalGSLGlobalStatusPtr->statusDescription = gsl_strerror( my_gsl_error );
00095   lalGSLGlobalStatusPtr->statusCode        = my_gsl_error;
00096   lalGSLGlobalStatusPtr->file              = file;
00097   lalGSLGlobalStatusPtr->line              = line;
00098   LALError( lalGSLGlobalStatusPtr, reason );
00099   LALTrace( lalGSLGlobalStatusPtr, 1 );
00100   return;
00101 }

Generated on Mon Oct 13 02:31:49 2008 for LAL by  doxygen 1.5.2