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