00001 00002 00003 00004 00005 00006 00007 // =========================================================== 00008 // 00009 // Copyright (C) 2005-2007, all rights reserved by 00010 // - Institute of Telematics, Universitaet Karlsruhe (TH) 00011 // 00012 // More information and contact: 00013 // https://projekte.tm.uka.de/trac/NSIS 00014 // 00015 // This program is free software; you can redistribute it and/or modify 00016 // it under the terms of the GNU General Public License as published by 00017 // the Free Software Foundation; version 2 of the License 00018 // 00019 // This program is distributed in the hope that it will be useful, 00020 // but WITHOUT ANY WARRANTY; without even the implied warranty of 00021 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 00022 // GNU General Public License for more details. 00023 // 00024 // You should have received a copy of the GNU General Public License along 00025 // with this program; if not, write to the Free Software Foundation, Inc., 00026 // 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. 00027 // 00028 // =========================================================== 00029 00044 #ifndef CLEANUP_HANDLER_H 00045 #define CLEANUP_HANDLER_H 00046 00047 #include <pthread.h> 00048 00049 namespace protlib { 00050 00055 00056 00065 #define install_cleanup(f,m) pthread_cleanup_push((void (*)(void *)) f, (void *) m) 00066 00068 00071 #define install_cleanup_mutex(m) install_cleanup(pthread_mutex_unlock,m) 00072 00074 00076 #define install_cleanup_mutex_lock(m) install_cleanup_mutex(m) pthread_mutex_lock(m) 00077 00079 00082 #define install_cleanup_thread_lock(ttype,tp) install_cleanup(call_unlock<ttype>,tp) tp->lock() 00083 00085 00088 #define uninstall_cleanup(exec) pthread_cleanup_pop(exec) 00089 00091 00094 template <class T> void call_unlock(void* pobj) { 00095 T* t; 00096 t = static_cast<T*>(pobj); 00097 t->unlock(); 00098 } // end call_unlock<T> 00099 00101 00102 inline void call_void_fun(void (*f)()) { 00103 f(); 00104 } // end call_void_fun 00105 00107 00108 } // end namespace protlib 00109 #endif