LoCondition.C

00001 /**
00002    \file  Robots/LoBot/misc/LoCondition.C
00003    \brief This file defines the non-inline member functions of the
00004    lobot::Condition class.
00005 */
00006 
00007 // //////////////////////////////////////////////////////////////////// //
00008 // The iLab Neuromorphic Vision C++ Toolkit - Copyright (C) 2000-2005   //
00009 // by the University of Southern California (USC) and the iLab at USC.  //
00010 // See http://iLab.usc.edu for information about this project.          //
00011 // //////////////////////////////////////////////////////////////////// //
00012 // Major portions of the iLab Neuromorphic Vision Toolkit are protected //
00013 // under the U.S. patent ``Computation of Intrinsic Perceptual Saliency //
00014 // in Visual Environments, and Applications'' by Christof Koch and      //
00015 // Laurent Itti, California Institute of Technology, 2001 (patent       //
00016 // pending; application number 09/912,225 filed July 23, 2001; see      //
00017 // http://pair.uspto.gov/cgi-bin/final/home.pl for current status).     //
00018 // //////////////////////////////////////////////////////////////////// //
00019 // This file is part of the iLab Neuromorphic Vision C++ Toolkit.       //
00020 //                                                                      //
00021 // The iLab Neuromorphic Vision C++ Toolkit is free software; you can   //
00022 // redistribute it and/or modify it under the terms of the GNU General  //
00023 // Public License as published by the Free Software Foundation; either  //
00024 // version 2 of the License, or (at your option) any later version.     //
00025 //                                                                      //
00026 // The iLab Neuromorphic Vision C++ Toolkit is distributed in the hope  //
00027 // that it will be useful, but WITHOUT ANY WARRANTY; without even the   //
00028 // implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR      //
00029 // PURPOSE.  See the GNU General Public License for more details.       //
00030 //                                                                      //
00031 // You should have received a copy of the GNU General Public License    //
00032 // along with the iLab Neuromorphic Vision C++ Toolkit; if not, write   //
00033 // to the Free Software Foundation, Inc., 59 Temple Place, Suite 330,   //
00034 // Boston, MA 02111-1307 USA.                                           //
00035 // //////////////////////////////////////////////////////////////////// //
00036 //
00037 // Primary maintainer for this file: mviswana usc edu
00038 // $HeadURL: svn://isvn.usc.edu/software/invt/trunk/saliency/src/Robots/LoBot/thread/LoCondition.C $
00039 // $Id: LoCondition.C 13523 2010-06-07 00:22:03Z mviswana $
00040 //
00041 
00042 //---------------------- ALTERNATIVE DEFINITION -------------------------
00043 
00044 // In case pthreads is missing
00045 #ifndef INVT_HAVE_LIBPTHREAD
00046 
00047 #include "Robots/LoBot/thread/LoCondition.H"
00048 #include "Robots/LoBot/misc/LoExcept.H"
00049 
00050 namespace lobot {
00051 
00052 // Constructors
00053 Condition::Condition()
00054    : m_mutex(0), m_cond(0)
00055 {
00056    throw missing_libs(MISSING_PTHREAD) ;
00057 }
00058 
00059 Condition::AutoMutex::AutoMutex(pthread_mutex_t&)
00060    : mutex(0)
00061 {}
00062 
00063 // Destructors
00064 Condition::~Condition(){}
00065 Condition::AutoMutex::~AutoMutex(){}
00066 
00067 } // end of namespace encapsulating above empty definition
00068 
00069 #else // pthreads available ==> the real McCoy
00070 
00071 //------------------------------ HEADERS --------------------------------
00072 
00073 // lobot headers
00074 #include "Robots/LoBot/thread/LoCondition.H"
00075 #include "Robots/LoBot/misc/LoExcept.H"
00076 
00077 //----------------------------- NAMESPACE -------------------------------
00078 
00079 namespace lobot {
00080 
00081 //-------------------------- INITIALIZATION -----------------------------
00082 
00083 Condition::Condition()
00084 {
00085    if (pthread_mutex_init(&m_mutex, 0) != 0)
00086       throw thread_error(MUTEX_INIT_ERROR) ;
00087    if (pthread_cond_init(&m_cond, 0) != 0) {
00088       pthread_mutex_destroy(&m_mutex) ;
00089       throw thread_error(COND_INIT_ERROR) ;
00090    }
00091 }
00092 
00093 Condition::AutoMutex::AutoMutex(pthread_mutex_t& m)
00094    : mutex(m)
00095 {
00096    pthread_mutex_lock(&mutex) ;
00097 }
00098 
00099 //----------------------------- CLEAN-UP --------------------------------
00100 
00101 Condition::~Condition()
00102 {
00103    pthread_cond_destroy (&m_cond) ;
00104    pthread_mutex_destroy(&m_mutex);
00105 }
00106 
00107 Condition::AutoMutex::~AutoMutex()
00108 {
00109    pthread_mutex_unlock(&mutex) ;
00110 }
00111 
00112 //-----------------------------------------------------------------------
00113 
00114 } // end of namespace encapsulating this file's definitions
00115 
00116 #endif // INVT_HAVE_PTHREAD
00117 
00118 /* So things look consistent in everyone's emacs... */
00119 /* Local Variables: */
00120 /* indent-tabs-mode: nil */
00121 /* End: */
Generated on Sun May 8 08:05:55 2011 for iLab Neuromorphic Vision Toolkit by  doxygen 1.6.3