Tervel  1.0.0
A collection of wait-free containers and algorithms.
mcas_casrow.h
Go to the documentation of this file.
1 /*
2 The MIT License (MIT)
3 
4 Copyright (c) 2015 University of Central Florida's Computer Software Engineering
5 Scalable & Secure Systems (CSE - S3) Lab
6 
7 Permission is hereby granted, free of charge, to any person obtaining a copy
8 of this software and associated documentation files (the "Software"), to deal
9 in the Software without restriction, including without limitation the rights
10 to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
11 copies of the Software, and to permit persons to whom the Software is
12 furnished to do so, subject to the following conditions:
13 
14 The above copyright notice and this permission notice shall be included in
15 all copies or substantial portions of the Software.
16 
17 THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
18 IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
19 FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
20 AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
21 LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
22 OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
23 THE SOFTWARE.
24 */
25 #ifndef TERVEL_MCAS_CASROW_H_
26 #define TERVEL_MCAS_CASROW_H_
27 
28 #include <tervel/util/info.h>
30 
31 namespace tervel {
32 namespace algorithms {
33 namespace wf {
34 namespace mcas {
35 
36 template<class T>
37 class Helper;
38 
44 template<class T>
45 class CasRow {
46  public:
47  CasRow<T>() {}
48 
49  CasRow<T>(std::atomic<T> *address, T expected_value, T new_value)
50  : address_ {address}
51  , expected_value_ {expected_value}
52  , new_value_ {new_value} {}
53 
54  ~CasRow<T>() {}
55 
56 
57  friend bool operator<(const CasRow<T>& a, const CasRow<T>& b) {
58  return ((uintptr_t)a.address_) < ((uintptr_t)b.address_);
59  };
60  friend bool operator>(const CasRow<T>& a, const CasRow<T>& b) {
61  return ((uintptr_t)a.address_) > ((uintptr_t)b.address_);
62  };
63  friend bool operator==(const CasRow<T>& a, const CasRow<T>& b) {
64  return ((uintptr_t)a.address_) == ((uintptr_t)b.address_);
65  };
66  friend bool operator!=(const CasRow<T>& a, const CasRow<T>& b) {
67  return ((uintptr_t)a.address_) != ((uintptr_t)b.address_);
68  };
69 
77  friend void swap(CasRow& a, CasRow& b) {
78  using std::swap;
81  swap(a.address_, b.address_);
82  };
83 
84  std::atomic<T> *address_;
87  std::atomic<Helper<T> *>helper_;
88 }; // Class CasRow
89 
90 } // namespace mcas
91 } // namespace wf
92 } // namespace algorithms
93 } // namespace tervel
94 #endif // TERVEL_MCAS_CASROW_H_
This class is used to represent a one of the M CAS operations performed by an MCAS operation...
Definition: mcas_casrow.h:45
friend bool operator!=(const CasRow< T > &a, const CasRow< T > &b)
Definition: mcas_casrow.h:66
T expected_value_
Definition: mcas_casrow.h:85
TODO(steven):
Definition: mcas.h:36
friend bool operator>(const CasRow< T > &a, const CasRow< T > &b)
Definition: mcas_casrow.h:60
std::atomic< T > * address_
Definition: mcas_casrow.h:82
std::atomic< Helper< T > * > helper_
Definition: mcas_casrow.h:87
friend bool operator==(const CasRow< T > &a, const CasRow< T > &b)
Definition: mcas_casrow.h:63
T new_value_
Definition: mcas_casrow.h:86
friend void swap(CasRow &a, CasRow &b)
This funciton is used when the MCAS operation is sorted to re-arrange the CasRows so they are sorted ...
Definition: mcas_casrow.h:77
This class is the MCAS operation's helper.
Definition: mcas_casrow.h:37