Tervel  1.0.0
A collection of wait-free containers and algorithms.
progress_assurance.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_UTIL_PROGRESS_ASSURANCE_H_
26 #define TERVEL_UTIL_PROGRESS_ASSURANCE_H_
27 
28 #include <atomic>
29 #include <memory>
30 #include <assert.h>
31 #include <tervel/util/info.h>
32 #include <tervel/util/util.h>
34 
35 
36 namespace tervel {
37 namespace util {
38 
39 namespace memory {
40 namespace hp {
41  class Element;
42 }
43 }
44 
52 class OpRecord : public memory::hp::Element {
53  public:
54  OpRecord() {}
55 
62  virtual void help_complete() = 0;
63 
73  bool on_watch(std::atomic<void *> *address, void *expected) {
74  return true;
75  }
76 
84  bool on_is_watched() {return false;}
90  void on_unwatch() {}
91 
92 
93  private:
95 };
96 
97 
107  public:
111  //static constexpr size_t MAX_FAILURES = TERVEL_PROG_ASSUR_LIMIT;
112 
117  static constexpr size_t HELP_DELAY = TERVEL_PROG_ASSUR_DELAY;
118 
119 
120  class Limit {
121  public:
122  explicit Limit(size_t limit = TERVEL_PROG_ASSUR_LIMIT)
123  : counter_(limit) {}
124 
125  bool isDelayed(size_t val = 1) {
126  size_t temp = counter_;
127  counter_ -= val;
128  return (temp == 0);
129  }
130 
131  void reset(size_t limit = TERVEL_PROG_ASSUR_LIMIT) {
132  counter_ = limit;
133  }
134  private:
135  size_t counter_;
136  };
137 
138  explicit ProgressAssurance(size_t num_threads)
139  : op_table_(new std::atomic<OpRecord *>[num_threads]() )
140  , num_threads_ {num_threads} {}
141 
151  static void check_for_announcement(ProgressAssurance * const progress_assuarance =
152  nullptr) {
153  static __thread size_t delay_count = HELP_DELAY;
154  static __thread size_t help_id = 0;
155 
156  if (delay_count-- == 0) {
157  delay_count = HELP_DELAY;
158  if (progress_assuarance == nullptr) {
160  p_check_for_announcement(help_id);
161  } else {
162  progress_assuarance->p_check_for_announcement(help_id);
163  }
164  }
165  }
166 
172  static void make_announcement(OpRecord *op, const uint64_t tid =
173  tervel::tl_thread_info->get_thread_id(), ProgressAssurance * const prog_assur =
174  tervel::tl_thread_info->get_progress_assurance()) {
175  prog_assur->p_make_announcement(op, tid);
176  }
177 
178  private:
183  void p_check_for_announcement(size_t &hpos);
184 
190  void p_make_announcement(OpRecord *op, const uint64_t tid =
191  tervel::tl_thread_info->get_thread_id());
192 
197  std::unique_ptr<std::atomic<OpRecord *>[]> op_table_;
198 
202  const size_t num_threads_;
203 
205 };
206 
207 } // namespace util
208 } // namespace tervel
209 
210 #endif // TERVEL_UTIL_PROGRESS_ASSURANCE_H_
virtual void help_complete()=0
Implementations of this function that upon its return the operation described in the OpRecord has bee...
virtual void on_unwatch()
This function is used to remove a strong watch on an Element.
Definition: hp_element.h:106
static void check_for_announcement(ProgressAssurance *const progress_assuarance=nullptr)
This function checks at most one position in the op_table_ for an OPRecod If one is found it will cal...
Definition: progress_assurance.h:151
bool on_watch(std::atomic< void * > *address, void *expected)
This function is used to achieve a strong watch on an Element.
Definition: progress_assurance.h:73
OpRecord()
Definition: progress_assurance.h:54
void p_make_announcement(OpRecord *op, const uint64_t tid=tervel::tl_thread_info->get_thread_id())
This function places the.
TODO(steven):
Definition: mcas.h:36
Limit(size_t limit=TERVEL_PROG_ASSUR_LIMIT)
Definition: progress_assurance.h:122
STL namespace.
size_t counter_
Definition: progress_assurance.h:135
bool on_is_watched()
This function is used to check a strong watch on an Element.
Definition: progress_assurance.h:84
DISALLOW_COPY_AND_ASSIGN(OpRecord)
This class is used for the creation of Hazard Pointer Protected Objects Objects which extend it have ...
Definition: hp_element.h:53
const size_t num_threads_
The number of threads that are using this operation table.
Definition: progress_assurance.h:202
static void make_announcement(OpRecord *op, const uint64_t tid=tervel::tl_thread_info->get_thread_id(), ProgressAssurance *const prog_assur=tervel::tl_thread_info->get_progress_assurance())
This function places the.
Definition: progress_assurance.h:172
__thread ThreadContext * tl_thread_info
#define TERVEL_PROG_ASSUR_DELAY
Definition: util.h:90
This class is used to create Operation Records.
Definition: progress_assurance.h:52
This class represents the progress assurance scheme employed by our library.
Definition: progress_assurance.h:106
virtual bool on_watch(std::atomic< void * > *address, void *expected)
This function is used to achieve a strong watch on an Element.
Definition: hp_element.h:91
virtual bool on_is_watched()
This function is used to check a strong watch on an Element.
Definition: hp_element.h:101
void p_check_for_announcement(size_t &hpos)
This function checks at most one position in the op_table_ for an OPRecod If one is found it will cal...
#define TERVEL_PROG_ASSUR_LIMIT
Definition: util.h:121
static constexpr size_t HELP_DELAY
Const used to delay an announcement.
Definition: progress_assurance.h:117
bool isDelayed(size_t val=1)
Definition: progress_assurance.h:125
std::unique_ptr< std::atomic< OpRecord * >[]> op_table_
Table for storing operation records, each thread has its own position that corresponds to its thread ...
Definition: progress_assurance.h:197
Definition: progress_assurance.h:120
void reset(size_t limit=TERVEL_PROG_ASSUR_LIMIT)
Definition: progress_assurance.h:131
util::ProgressAssurance *const get_progress_assurance()
ProgressAssurance(size_t num_threads)
Definition: progress_assurance.h:138
DISALLOW_COPY_AND_ASSIGN(ProgressAssurance)
void on_unwatch()
This function is used to remove a strong watch on an Element.
Definition: progress_assurance.h:90