Galois
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Pages
CheckedObject.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_CHECKEDOBJECT_H
21 #define GALOIS_CHECKEDOBJECT_H
22 
23 #include "galois/config.h"
24 #include "galois/runtime/Context.h"
25 
26 namespace galois {
27 
33 template <typename T>
35  T val;
36 
37 public:
38  template <typename... Args>
39  GChecked(Args&&... args) : val(std::forward<Args>(args)...) {}
40 
42  galois::runtime::acquire(this, m);
43  return val;
44  }
45 
46  const T& get(galois::MethodFlag m = MethodFlag::WRITE) const {
47  galois::runtime::acquire(const_cast<GChecked*>(this), m);
48  return val;
49  }
50 };
51 
52 template <>
53 class GChecked<void> : public galois::runtime::Lockable {
54 public:
55  void get(galois::MethodFlag m = MethodFlag::WRITE) const {
56  galois::runtime::acquire(const_cast<GChecked*>(this), m);
57  }
58 };
59 
60 } // namespace galois
61 
62 #endif // _GALOIS_CHECKEDOBJECT_H
Conflict-checking wrapper for any type.
Definition: CheckedObject.h:34
All objects that may be locked (nodes primarily) must inherit from Lockable.
Definition: libgalois/include/galois/runtime/Context.h:83
GChecked(Args &&...args)
Definition: CheckedObject.h:39
void acquire(Lockable *lockable, galois::MethodFlag m)
Master function which handles conflict detection used to acquire a lockable thing.
Definition: libgalois/include/galois/runtime/Context.h:218
MethodFlag
What should the runtime do when executing a method.
Definition: MethodFlags.h:34