1 // ----------------------------------------------------------------------------
2 //	fl_lock.h
3 //
4 // Copyright (C) 2007
5 //		Stelios Bounanos, M0GLD
6 //
7 // This file is part of fldigi.
8 //
9 // fldigi 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 // fldigi 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 #ifndef FL_LOCK_H_
24 #define FL_LOCK_H_
25 
26 // disabled calls
27 #define FL_LOCK_D(x)   ((void)0)
28 #define FL_UNLOCK_D(x) ((void)0)
29 #define FL_AWAKE_D(x)  ((void)0)
30 // enabled calls
31 #define FL_LOCK_E(x)   FL_LOCK(x)
32 #define FL_UNLOCK_E(x) FL_UNLOCK(x)
33 #define FL_AWAKE_E(x)  FL_AWAKE(x)
34 
35 #if !defined(NDEBUG) && !defined(NO_LOCKS)
36 #	include <FL/Fl.H>
37 #endif
38 
39 #ifdef NDEBUG
40 #	define FL_LOCK(x)   Fl::lock(x)
41 #	define FL_UNLOCK(x) Fl::unlock(x)
42 #	define FL_AWAKE(x)  Fl::awake(x)
43 #else // debugging
44 #	include <stacktrace.h>
45 
46 #	ifndef NO_LOCKS
47 #               include "debug.h"
48 #		define FL_LOCK(x)                                       \
49                 do {                                                    \
50                         switch (GET_THREAD_ID()) {                      \
51                         case TRX_TID:                                   \
52                                 LOG_ERROR("trx lock");			\
53                                 break;                                  \
54                         case FLMAIN_TID:                                \
55                                 LOG_WARN("flrun lock");			\
56                                 break;                                  \
57                         default:                                        \
58                                 LOG_VERBOSE("lock");			\
59                         }                                               \
60                         pstack_maybe();                                 \
61                         Fl::lock(x);                                    \
62                 } while (0);
63 
64 #		define FL_UNLOCK(x) Fl::unlock(x)
65 #		define FL_AWAKE(x)  Fl::awake(x)
66 #	else // no locks
67 #		define FL_LOCK(x)   ((void)0)
68 #		define FL_UNLOCK(x) ((void)0)
69 #		define FL_AWAKE(x)  ((void)0)
70 #	endif // NO_LOCKS
71 #endif // NDEBUG
72 
73 #endif // FL_LOCK_H_
74 
75 // Local Variables:
76 // mode: c++
77 // c-file-style: "linux"
78 // End:
79