1 // ----------------------------------------------------------------------------
2 //
3 // flxmlrpc Copyright (c) 2015 by W1HKJ, Dave Freese <iam_w1hkj@w1hkj.com>
4 //
5 // XmlRpc++ Copyright (c) 2002-2008 by Chris Morley
6 //
7 // This file is part of fldigi
8 //
9 // flxmlrpc is free software; you can redistribute it and/or modify
10 // it under the terms of the GNU Lesser 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 // You should have received a copy of the GNU General Public License
15 // along with this program.  If not, see <http://www.gnu.org/licenses/>.
16 // ----------------------------------------------------------------------------
17 
18 #ifndef _XMLRPCMUTEX_H_
19 #define _XMLRPCMUTEX_H_
20 
21 #if defined(_MSC_VER)
22 # pragma warning(disable:4786)    // identifier was truncated in debug info
23 #endif
24 
25 namespace XmlRpc {
26 
27   //! A simple platform-independent mutex API implemented for posix and windows.
28   class XmlRpcMutex {
29   public:
30     //! Construct a Mutex object.
XmlRpcMutex()31     XmlRpcMutex() : _pMutex(0) {}
32 
33     //! Destroy a Mutex object.
34     ~XmlRpcMutex();
35 
36     //! Wait for the mutex to be available and then acquire the lock.
37     void acquire();
38 
39     //! Release the mutex.
40     void release();
41 
42     //! Utility class to acquire a mutex at construction and release it when destroyed.
43     struct AutoLock {
44       //! Acquire the mutex at construction
AutoLockAutoLock45       AutoLock(XmlRpcMutex& m) : _m(m) { _m.acquire(); }
46       //! Release at destruction
~AutoLockAutoLock47       ~AutoLock() { _m.release(); }
48       //! The mutex being held
49       XmlRpcMutex& _m;
50     };
51 
52   private:
53 
54     //! Native Mutex object
55     void* _pMutex;
56 
57   };  // class XmlRpcMutex
58 
59 }  // namespace XmlRpc
60 
61 #endif	//  _XMLRPCMUTEX_H_
62