~ubuntu-branches/ubuntu/wily/flrig/wily

« back to all changes in this revision

Viewing changes to src/support/threads.cxx

  • Committer: Package Import Robot
  • Author(s): Kamal Mostafa
  • Date: 2014-10-25 11:17:10 UTC
  • mfrom: (1.1.1)
  • Revision ID: package-import@ubuntu.com-20141025111710-n32skgya3l9u1brw
Tags: 1.3.17-1
* New upstream release (Closes: #761839)
* Debian Standards-Version: 3.9.6

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
// ----------------------------------------------------------------------------
 
2
//      threads.cxx
 
3
//
 
4
// Copyright (C) 2014
 
5
//              Stelios Bounanos, M0GLD
 
6
//              David Freese, W1HKJ
 
7
//
 
8
// This file is part of fldigi.
 
9
//
 
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.
 
14
//
 
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.
 
19
//
 
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
// ----------------------------------------------------------------------------
 
23
 
 
24
#include <stdio.h>
 
25
#include <stdlib.h>
 
26
 
 
27
#include "threads.h"
 
28
 
 
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;
 
36
 
 
37
// Change to 1 to observe guard lock/unlock processing on stdout
 
38
#define DEBUG_GUARD_LOCK 0
 
39
 
 
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);
 
44
}
 
45
 
 
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);
 
50
}
 
51
 
 
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";
 
59
                return "Unknown";
 
60
        }