+ int thread_id = id_to_int(tid);
+ int old_size = thrd_dist_maps.size();
+
+ if (old_size <= thread_id) {
+ thrd_dist_maps.resize(thread_id + 1);
+ for (int i = old_size;i < thread_id + 1;i++) {
+ thrd_dist_maps[i] = new dist_map_t(16);
+ }
+ }
+
+ return thrd_dist_maps[thread_id];
+}
+
+node_set_t * WaitObj::getTargetNodes(thread_id_t tid)
+{
+ int thread_id = id_to_int(tid);
+ int old_size = thrd_target_nodes.size();
+
+ if (old_size <= thread_id) {
+ thrd_target_nodes.resize(thread_id + 1);
+ for (int i = old_size;i < thread_id + 1;i++) {
+ thrd_target_nodes[i] = new node_set_t(16);
+ }
+ }
+
+ return thrd_target_nodes[thread_id];
+}
+
+/**
+ * Increment action counter for thread tid
+ * @return true if the counter for tid expires
+ */
+bool WaitObj::incr_counter(thread_id_t tid)
+{
+ int thread_id = id_to_int(tid);
+
+ /* thrd_action_counters.resize does not work here */
+ while (thrd_action_counters.size() <= (uint) thread_id) {
+ thrd_action_counters.push_back(0);
+ }
+
+ thrd_action_counters[thread_id]++;
+ if (thrd_action_counters[thread_id] > COUNTER_THRESHOLD) {
+ thrd_action_counters[thread_id] = 0;
+ return true;
+ }
+
+ return false;
+}
+
+void WaitObj::clear_waiting_for()
+{
+ thrd_id_set_iter * iter = waiting_for.iterator();
+ while (iter->hasNext()) {
+ thread_id_t tid = iter->next();
+ int index = id_to_int(tid);
+ thrd_action_counters[index] = 0;
+
+ /* thrd_dist_maps are not reset because distances
+ * will be overwritten when node targets are added
+ * thrd_dist_maps[index]->reset(); */
+
+ node_set_t * target_nodes = getTargetNodes(tid);
+ target_nodes->reset();
+ }
+
+ delete iter;
+