Galois
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Pages
PaddedLock.h
Go to the documentation of this file.
1 /*
2  * This file belongs to the Galois project, a C++ library for exploiting
3  * parallelism. The code is being released under the terms of the 3-Clause BSD
4  * License (a copy is located in LICENSE.txt at the top-level directory).
5  *
6  * Copyright (C) 2018, The University of Texas at Austin. All rights reserved.
7  * UNIVERSITY EXPRESSLY DISCLAIMS ANY AND ALL WARRANTIES CONCERNING THIS
8  * SOFTWARE AND DOCUMENTATION, INCLUDING ANY WARRANTIES OF MERCHANTABILITY,
9  * FITNESS FOR ANY PARTICULAR PURPOSE, NON-INFRINGEMENT AND WARRANTIES OF
10  * PERFORMANCE, AND ANY WARRANTY THAT MIGHT OTHERWISE ARISE FROM COURSE OF
11  * DEALING OR USAGE OF TRADE. NO WARRANTY IS EITHER EXPRESS OR IMPLIED WITH
12  * RESPECT TO THE USE OF THE SOFTWARE OR DOCUMENTATION. Under no circumstances
13  * shall University be liable for incidental, special, indirect, direct or
14  * consequential damages or loss of profits, interruption of business, or
15  * related expenses which may arise from use of Software or Documentation,
16  * including but not limited to those resulting from defects in Software and/or
17  * Documentation, or loss or inaccuracy of data of any kind.
18  */
19 
20 #ifndef GALOIS_SUBSTRATE_PADDEDLOCK_H
21 #define GALOIS_SUBSTRATE_PADDEDLOCK_H
22 
25 
26 namespace galois {
27 namespace substrate {
28 
31 template <bool concurrent>
32 class PaddedLock;
33 
34 template <>
35 class PaddedLock<true> {
36  mutable CacheLineStorage<SimpleLock> Lock;
37 
38 public:
39  void lock() const { Lock.get().lock(); }
40  bool try_lock() const { return Lock.get().try_lock(); }
41  void unlock() const { Lock.get().unlock(); }
42 };
43 
44 template <>
45 class PaddedLock<false> {
46 public:
47  void lock() const {}
48  bool try_lock() const { return true; }
49  void unlock() const {}
50 };
51 
52 } // end namespace substrate
53 } // end namespace galois
54 
55 #endif
bool try_lock() const
Definition: PaddedLock.h:40
void unlock() const
Definition: PaddedLock.h:49
void lock() const
Definition: PaddedLock.h:39
Definition: CacheLineStorage.h:32
void unlock() const
Definition: PaddedLock.h:41
bool try_lock() const
Definition: PaddedLock.h:48
PaddedLock is a spinlock.
Definition: PaddedLock.h:32
void lock() const
Definition: PaddedLock.h:47