OpenMAMA
MamdaLock.h
Go to the documentation of this file.
1 /* $Id$
2  *
3  * OpenMAMA: The open middleware agnostic messaging API
4  * Copyright (C) 2011 NYSE Technologies, Inc.
5  *
6  * This library is free software; you can redistribute it and/or
7  * modify it under the terms of the GNU Lesser General Public
8  * License as published by the Free Software Foundation; either
9  * version 2.1 of the License, or (at your option) any later version.
10  *
11  * This library is distributed in the hope that it will be useful,
12  * but WITHOUT ANY WARRANTY; without even the implied warranty of
13  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
14  * Lesser General Public License for more details.
15  *
16  * You should have received a copy of the GNU Lesser General Public
17  * License along with this library; if not, write to the Free Software
18  * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA
19  * 02110-1301 USA
20  */
21 
22 #ifndef MamdaLockH
23 #define MamdaLockH
24 
25 #include <mamda/MamdaConfig.h>
26 
27 namespace Wombat
28 {
29  #define ACQUIRE_WLOCK(lock) (lock).acquire(MamdaLock::WRITE)
30  #define ACQUIRE_RLOCK(lock) (lock).acquire(MamdaLock::READ)
31  #define RELEASE_WLOCK(lock) (lock).release(MamdaLock::WRITE)
32  #define RELEASE_RLOCK(lock) (lock).release(MamdaLock::READ)
33 
34  #define ACQUIRE_LOCK(lock, writeNeeded) \
35  do { \
36  if (writeNeeded) \
37  (lock).acquire(MamdaLock::WRITE); \
38  else \
39  (lock).acquire(MamdaLock::READ); \
40  } while (0)
41 
42  #define RELEASE_LOCK(lock, isWrite) \
43  do { \
44  if (isWrite) \
45  (lock).release(MamdaLock::WRITE); \
46  else \
47  (lock).release(MamdaLock::READ); \
48  } while (0)
49 
50 
51  class MAMDAExpDLL MamdaLock
52  {
53  public:
54  enum Scheme
55  {
57  EXCLUSIVE
58  };
59 
60  enum Type
61  {
63  WRITE
64  };
65 
66  MamdaLock (Scheme scheme,
67  const char* context,
68  int threads = 0);
69 
70  ~MamdaLock ();
71 
72  bool acquire (Type type);
73  bool release (Type type);
74  static const char* type (Type type);
75  static const char* scheme (Scheme scheme);
76 
77  static bool lockingEnabled()
78  {
79  // This is to be a configuration parameter at some point
80  return true;
81  }
82 
83  private:
84  MamdaLock (const MamdaLock& lock);
85  class MamdaLockImpl;
86  MamdaLockImpl& mImpl;
87  };
88 
89  #endif // MamdaLockH
90 
91 
92 } // namsespace Wombat


© 2012 Linux Foundation