Fawkes API  Fawkes Development Version
mutex_data.h
1 
2 /***************************************************************************
3  * mutex_data.h - mutex data
4  *
5  * Generated: Thu Sep 14 17:44:54 2006
6  * Copyright 2006 Tim Niemueller [www.niemueller.de]
7  *
8  ****************************************************************************/
9 
10 /* This program is free software; you can redistribute it and/or modify
11  * it under the terms of the GNU General Public License as published by
12  * the Free Software Foundation; either version 2 of the License, or
13  * (at your option) any later version. A runtime exception applies to
14  * this software (see LICENSE.GPL_WRE file mentioned below for details).
15  *
16  * This program is distributed in the hope that it will be useful,
17  * but WITHOUT ANY WARRANTY; without even the implied warranty of
18  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
19  * GNU Library General Public License for more details.
20  *
21  * Read the full text in the LICENSE.GPL_WRE file in the doc directory.
22  */
23 
24 #ifndef __CORE_THREADING_MUTEX_DATA_H_
25 #define __CORE_THREADING_MUTEX_DATA_H_
26 
27 #include <pthread.h>
28 
29 #ifdef DEBUG_THREADING
30 #include <core/threading/thread.h>
31 #include <core/exception.h>
32 #include <cstring>
33 #include <cstdlib>
34 #include <cstdio>
35 #endif
36 
37 namespace fawkes {
38 
39 
40 /// @cond INTERNALS
41 /** Internal class of Mutexes, do not use directly.
42  */
43 class MutexData {
44  public:
45  pthread_mutex_t mutex;
46 
47 #ifdef DEBUG_THREADING
48  MutexData() {
49  lock_holder = strdup("Not locked");
50  }
51 
52  ~MutexData() {
53  if ( lock_holder ) {
54  free(lock_holder);
55  }
56  }
57 
58  char *lock_holder;
59 
60  void set_lock_holder()
61  {
62  if ( lock_holder ) {
63  free(lock_holder);
64  }
65  try {
66  Thread *ct = Thread::current_thread();
67  if ( ct ) {
68  lock_holder = strdup(ct->name());
69  } else {
70  lock_holder = strdup("Unknown");
71  }
72  } catch (Exception &e) {
73  asprintf(&lock_holder, "Unknown: failed to get thread (%s)", e.what());
74  }
75  }
76 
77  void unset_lock_holder() {
78  if ( lock_holder ) {
79  free(lock_holder);
80  }
81  lock_holder = strdup("Not locked");
82  }
83 
84 #endif
85 };
86 /// @endcond
87 
88 
89 } // end namespace fawkes
90 
91 #endif
Fawkes library namespace.
static Thread * current_thread()
Get the Thread instance of the currently running thread.
Definition: thread.cpp:1318