1
// ----------------------------------------------------------------------------
5
// Stelios Bounanos, M0GLD
8
// This file is part of fldigi.
10
// fldigi 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 3 of the License, or
13
// (at your option) any later version.
15
// fldigi is distributed in the hope that it will be useful,
16
// but WITHOUT ANY WARRANTY; without even the implied warranty of
17
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
18
// GNU General Public License for more details.
20
// You should have received a copy of the GNU General Public License
21
// along with this program. If not, see <http://www.gnu.org/licenses/>.
22
// ----------------------------------------------------------------------------
29
/// This ensures that a mutex is always unlocked when leaving a function or block.
30
extern pthread_mutex_t mutex_rcv_socket;
31
extern pthread_mutex_t mutex_serial;
32
extern pthread_mutex_t mutex_xmlrpc;
33
extern pthread_mutex_t mutex_queA;
34
extern pthread_mutex_t mutex_queB;
35
extern pthread_mutex_t mutex_ptt;
37
// Change to 1 to observe guard lock/unlock processing on stdout
38
#define DEBUG_GUARD_LOCK 0
40
guard_lock::guard_lock(pthread_mutex_t* m, int h) : mutex(m), how(h) {
41
pthread_mutex_lock(mutex);
42
if (how != 0 && DEBUG_GUARD_LOCK)
43
printf("lock %s : %d\n", name(mutex), how);
46
guard_lock::~guard_lock(void) {
47
pthread_mutex_unlock(mutex);
48
if (how != 0 && DEBUG_GUARD_LOCK)
49
printf("unlock %s : %d\n", name(mutex), how);
52
const char * guard_lock::name(pthread_mutex_t *m) {
53
if (m == &mutex_ptt) return "PTT";
54
if (m == &mutex_queA) return "QueA";
55
if (m == &mutex_queB) return "QueB";
56
if (m == &mutex_rcv_socket) return "Rcv Socket";
57
if (m == &mutex_serial) return "Serial";
58
if (m == &mutex_xmlrpc) return "XmlRpc";