Fawkes API
Fawkes Development Version
|
00001 00002 /*************************************************************************** 00003 * mutex_data.h - mutex data 00004 * 00005 * Generated: Thu Sep 14 17:44:54 2006 00006 * Copyright 2006 Tim Niemueller [www.niemueller.de] 00007 * 00008 ****************************************************************************/ 00009 00010 /* This program is free software; you can redistribute it and/or modify 00011 * it under the terms of the GNU General Public License as published by 00012 * the Free Software Foundation; either version 2 of the License, or 00013 * (at your option) any later version. A runtime exception applies to 00014 * this software (see LICENSE.GPL_WRE file mentioned below for details). 00015 * 00016 * This program is distributed in the hope that it will be useful, 00017 * but WITHOUT ANY WARRANTY; without even the implied warranty of 00018 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 00019 * GNU Library General Public License for more details. 00020 * 00021 * Read the full text in the LICENSE.GPL_WRE file in the doc directory. 00022 */ 00023 00024 #ifndef __CORE_THREADING_MUTEX_DATA_H_ 00025 #define __CORE_THREADING_MUTEX_DATA_H_ 00026 00027 #include <pthread.h> 00028 00029 #ifdef DEBUG_THREADING 00030 #include <core/threading/thread.h> 00031 #include <core/exception.h> 00032 #include <cstring> 00033 #include <cstdlib> 00034 #include <cstdio> 00035 #endif 00036 00037 namespace fawkes { 00038 00039 00040 /// @cond INTERNALS 00041 /** Internal class of Mutexes, do not use directly. 00042 */ 00043 class MutexData { 00044 public: 00045 pthread_mutex_t mutex; 00046 00047 #ifdef DEBUG_THREADING 00048 MutexData() { 00049 lock_holder = strdup("Not locked"); 00050 } 00051 00052 ~MutexData() { 00053 if ( lock_holder ) { 00054 free(lock_holder); 00055 } 00056 } 00057 00058 char *lock_holder; 00059 00060 void set_lock_holder() 00061 { 00062 if ( lock_holder ) { 00063 free(lock_holder); 00064 } 00065 try { 00066 Thread *ct = Thread::current_thread(); 00067 if ( ct ) { 00068 lock_holder = strdup(ct->name()); 00069 } else { 00070 lock_holder = strdup("Unknown"); 00071 } 00072 } catch (Exception &e) { 00073 asprintf(&lock_holder, "Unknown: failed to get thread (%s)", e.what()); 00074 } 00075 } 00076 00077 void unset_lock_holder() { 00078 if ( lock_holder ) { 00079 free(lock_holder); 00080 } 00081 lock_holder = strdup("Not locked"); 00082 } 00083 00084 #endif 00085 }; 00086 /// @endcond 00087 00088 00089 } // end namespace fawkes 00090 00091 #endif