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/exception.h>
31# include <core/threading/thread.h>
32
33# include <cstdio>
34# include <cstdlib>
35# include <cstring>
36#endif
37
38namespace fawkes {
39
40/// @cond INTERNALS
41/** Internal class of Mutexes, do not use directly.
42 */
43class MutexData
44{
45public:
46 pthread_mutex_t mutex;
47
48#ifdef DEBUG_THREADING
49 MutexData()
50 {
51 lock_holder = strdup("Not locked");
52 }
53
54 ~MutexData()
55 {
56 if (lock_holder) {
57 free(lock_holder);
58 }
59 }
60
61 char *lock_holder;
62
63 void
64 set_lock_holder()
65 {
66 if (lock_holder) {
67 free(lock_holder);
68 }
69 try {
70 Thread *ct = Thread::current_thread();
71 if (ct) {
72 lock_holder = strdup(ct->name());
73 } else {
74 lock_holder = strdup("Unknown");
75 }
76 } catch (Exception &e) {
77 asprintf(&lock_holder, "Unknown: failed to get thread (%s)", e.what());
78 }
79 }
80
81 void
82 unset_lock_holder()
83 {
84 if (lock_holder) {
85 free(lock_holder);
86 }
87 lock_holder = strdup("Not locked");
88 }
89
90#endif
91};
92/// @endcond
93
94} // end namespace fawkes
95
96#endif
static Thread * current_thread()
Get the Thread instance of the currently running thread.
Definition: thread.cpp:1366
Fawkes library namespace.