+ action_list_t *list = generateSC(actions);
+ print_list(list);
+}
+
+bool SCAnalysis::merge(ClockVector *cv, const ModelAction *act, ClockVector *cv2) {
+ if (cv2->getClock(act->get_tid()) >= act->get_seq_number() && act->get_seq_number() != 0) {
+ cycleset.put(act, act);
+ }
+ return cv->merge(cv2);
+}
+
+ModelAction * SCAnalysis::getNextAction() {
+ ModelAction *act = NULL;
+ for (int i = 0; i <= maxthreads; i++) {
+ action_list_t *threadlist = &threadlists[i];
+ if (threadlist->empty())
+ continue;
+ ModelAction *first = threadlist->front();
+ if (act == NULL) {
+ act = first;
+ continue;
+ }
+ ClockVector *cv = cvmap.get(act);
+ if (cv->synchronized_since(first)) {
+ act = first;
+ }
+ }
+ if (act == NULL)
+ return act;
+ //print cycles in a nice way to avoid confusion
+ //make sure thread starts appear after the create
+ if (act->is_thread_start()) {
+ ModelAction *createact = execution->get_thread(act)->get_creation();
+ if (createact) {
+ action_list_t *threadlist = &threadlists[id_to_int(createact->get_tid())];
+ if (!threadlist->empty()) {
+ ModelAction *first = threadlist->front();
+ if (first->get_seq_number() <= createact->get_seq_number())
+ act = first;
+ }
+ }
+ }
+
+ //make sure that joins appear after the thread is finished
+ if (act->is_thread_join()) {
+ int jointhread = id_to_int(act->get_thread_operand()->get_id());
+ action_list_t *threadlist = &threadlists[jointhread];
+ if (!threadlist->empty()) {
+ act = threadlist->front();
+ }
+ }
+
+ return act;
+}
+
+action_list_t * SCAnalysis::generateSC(action_list_t *list) {
+ action_list_t *sclist = new action_list_t();
+ while (true) {
+ ModelAction *act = getNextAction();
+ if (act == NULL)
+ break;
+ thread_id_t tid = act->get_tid();
+ //remove action
+ threadlists[id_to_int(tid)].pop_front();
+ //add ordering constraints from this choice
+ if (updateConstraints(act)) {
+ //propagate changes if we have them
+ computeCV(list);
+ }
+ //add action to end
+ sclist->push_back(act);
+ }
+ return sclist;