1 // ----------------------------------------------------------------------------
2 //	fl_lock.h
3 //
4 // Copyright (C) 2007
5 //		Stelios Bounanos, M0GLD
6 //
7 // This file is part of FLAMP.
8 //
9 // This is free software; you can redistribute it and/or modify
10 // it under the terms of the GNU General Public License as published by
11 // the Free Software Foundation; either version 3 of the License, or
12 // (at your option) any later version.
13 //
14 // This software is distributed in the hope that it will be useful,
15 // but WITHOUT ANY WARRANTY; without even the implied warranty of
16 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
17 // GNU General Public License for more details.
18 //
19 // You should have received a copy of the GNU General Public License
20 // along with this program.  If not, see <http://www.gnu.org/licenses/>.
21 //
22 // ----------------------------------------------------------------------------
23 
24 #ifndef FL_LOCK_H_
25 #define FL_LOCK_H_
26 
27 // disabled calls
28 #define FL_LOCK_D(x)   ((void)0)
29 #define FL_UNLOCK_D(x) ((void)0)
30 #define FL_AWAKE_D(x)  ((void)0)
31 // enabled calls
32 #define FL_LOCK_E(x)   FL_LOCK(x)
33 #define FL_UNLOCK_E(x) FL_UNLOCK(x)
34 #define FL_AWAKE_E(x)  FL_AWAKE(x)
35 
36 #if !defined(NDEBUG) && !defined(NO_LOCKS)
37 #	include <FL/Fl.H>
38 #endif
39 
40 #ifdef NDEBUG
41 #	define FL_LOCK(x)   Fl::lock(x)
42 #	define FL_UNLOCK(x) Fl::unlock(x)
43 #	define FL_AWAKE(x)  Fl::awake(x)
44 #else // debugging
45 #	include <stacktrace.h>
46 
47 #	ifndef NO_LOCKS
48 #               include "debug.h"
49 #		define FL_LOCK(x)                                       \
50                 do {                                                    \
51                         switch (GET_THREAD_ID()) {                      \
52                         case TRX_TID:                                   \
53                                 LOG_ERROR("trx lock");			\
54                                 break;                                  \
55                         case FLMAIN_TID:                                \
56                                 LOG_WARN("flrun lock");			\
57                                 break;                                  \
58                         default:                                        \
59                                 LOG_VERBOSE("lock");			\
60                         }                                               \
61                         pstack_maybe();                                 \
62                         Fl::lock(x);                                    \
63                 } while (0);
64 
65 #		define FL_UNLOCK(x) Fl::unlock(x)
66 #		define FL_AWAKE(x)  Fl::awake(x)
67 #	else // no locks
68 #		define FL_LOCK(x)   ((void)0)
69 #		define FL_UNLOCK(x) ((void)0)
70 #		define FL_AWAKE(x)  ((void)0)
71 #	endif // NO_LOCKS
72 #endif // NDEBUG
73 
74 #endif // FL_LOCK_H_
75 
76 // Local Variables:
77 // mode: c++
78 // c-file-style: "linux"
79 // End:
80