ispar.c

Go to the documentation of this file.
00001 /*                         I S P A R . C
00002  * BRL-CAD
00003  *
00004  * Copyright (c) 2004-2006 United States Government as represented by
00005  * the U.S. Army Research Laboratory.
00006  *
00007  * This library is free software; you can redistribute it and/or
00008  * modify it under the terms of the GNU Lesser General Public License
00009  * as published by the Free Software Foundation; either version 2 of
00010  * the License, or (at your option) any later version.
00011  *
00012  * This library is distributed in the hope that it will be useful, but
00013  * WITHOUT ANY WARRANTY; without even the implied warranty of
00014  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
00015  * Library General Public License for more details.
00016  *
00017  * You should have received a copy of the GNU Lesser General Public
00018  * License along with this file; see the file named COPYING for more
00019  * information.
00020  */
00021 
00022 /** \addtogroup thread */
00023 /*@{*/
00024 /** @file ispar.c
00025  * @brief subroutine to determine if we are multi-threaded
00026  *
00027  *  This subroutine is separated off from parallel.c so that
00028  *  bu_bomb() and others can call it, without causing either
00029  *  parallel.c or semaphore.c to get referenced and thus causing
00030  *  the loader to drag in all the parallel processing stuff from
00031  *  the vendor library.
00032  *
00033  *  @author
00034  *      Michael John Muuss
00035  *
00036  *  @par Source -
00037  *  @n  The U. S. Army Research Laboratory
00038  *  @n  Aberdeen Proving Ground, Maryland  21005-5068  USA
00039  */
00040 
00041 #ifndef lint
00042 static const char RCSispar[] = "@(#)$Header: /cvsroot/brlcad/brlcad/src/libbu/ispar.c,v 14.14 2006/09/03 15:14:07 lbutler Exp $ (ARL)";
00043 #endif
00044 
00045 #include "common.h"
00046 
00047 #include <stdio.h>
00048 #include <math.h>
00049 #include <signal.h>
00050 #ifdef HAVE_SYS_TYPES_H
00051 #  include <sys/types.h>
00052 #endif
00053 #ifdef HAVE_UNISTD_H
00054 #  include <unistd.h>
00055 #endif
00056 
00057 #include "machine.h"
00058 #include "bu.h"
00059 
00060 
00061 int     bu_pid_of_initiating_thread = 0; /**< don't declare in include/bu.h */
00062 
00063 /**
00064  *                      B U _ I S _ P A R A L L E L
00065  *
00066  *  A clean way for bu_bomb() to tell if this is a parallel application.
00067  *  If bu_parallel() is active, this routine will return non-zero.
00068  */
00069 int
00070 bu_is_parallel(void)
00071 {
00072     if( bu_pid_of_initiating_thread != 0 )  return 1;
00073     return 0;
00074 }
00075 
00076 /**
00077  *                      B U _ K I L L _ P A R A L L E L
00078  *
00079  *  Used by bu_bomb() to help terminate parallel threads,
00080  *  without dragging in the whole parallel library if it isn't being used.
00081  */
00082 void
00083 bu_kill_parallel(void)
00084 {
00085 #ifndef _WIN32
00086     if( bu_pid_of_initiating_thread == 0 )  return;
00087     if( bu_pid_of_initiating_thread == getpid() )  return;
00088     (void)kill( bu_pid_of_initiating_thread, 9 );
00089 #endif
00090     return;
00091 }
00092 /*@}*/
00093 /*
00094  * Local Variables:
00095  * mode: C
00096  * tab-width: 8
00097  * c-basic-offset: 4
00098  * indent-tabs-mode: t
00099  * End:
00100  * ex: shiftwidth=4 tabstop=8
00101  */

Generated on Mon Sep 18 01:24:48 2006 for BRL-CAD by  doxygen 1.4.6