+ 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;
+ /* Find the earliest in SC ordering */
+ 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;
+
+
+ /* Find the model action with the earliest sequence number in case of a cycle.
+ */
+
+ for (int i = 0; i <= maxthreads; i++) {
+ action_list_t *threadlist = &threadlists[i];
+ if (threadlist->empty())
+ continue;
+ ModelAction *first = threadlist->front();
+ ClockVector *cv = cvmap.get(act);
+ ClockVector *cvfirst = cvmap.get(first);
+ if (first->get_seq_number()<act->get_seq_number()&&
+ (cv->synchronized_since(first)||!cvfirst->synchronized_since(act))) {
+ act=first;
+ }
+ }
+
+ /* See if hb demands an earlier action. */
+ for (int i = 0; i <= maxthreads; i++) {
+ action_list_t *threadlist = &threadlists[i];
+ if (threadlist->empty())
+ continue;
+ ModelAction *first = threadlist->front();
+ ClockVector *cv = act->get_cv();
+ if (cv->synchronized_since(first)) {
+ act = first;
+ }
+ }
+ 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;