Modified the implementation of usleep and make ModelExecution process "THREAD SLEEP...
[c11tester.git] / fuzzer.cc
index 550a0a16210e1c016315c97dd1f47c2601ddbdba..12396dd9dec0e4e97231fbd5e2dcce82b73f8958 100644 (file)
--- a/fuzzer.cc
+++ b/fuzzer.cc
@@ -2,25 +2,39 @@
 #include <stdlib.h>
 #include "threads-model.h"
 #include "model.h"
+#include "action.h"
 
-int Fuzzer::selectWrite(ModelAction *read, ModelVector<ModelAction *> * rf_set) {
-  int random_index = random() % rf_set->size();
-  return random_index;
+int Fuzzer::selectWrite(ModelAction *read, SnapVector<ModelAction *> * rf_set) {
+       int random_index = random() % rf_set->size();
+       return random_index;
 }
 
-Thread * Fuzzer::selectThread(Node *n, int * threadlist, int numthreads) {
-  int random_index = random() % numthreads;
-  int thread = threadlist[random_index];
-  thread_id_t curr_tid = int_to_id(thread);
-  return model->get_thread(curr_tid);
+Thread * Fuzzer::selectThread(int * threadlist, int numthreads) {
+       int random_index = random() % numthreads;
+       int thread = threadlist[random_index];
+       thread_id_t curr_tid = int_to_id(thread);
+       return model->get_thread(curr_tid);
 }
 
 Thread * Fuzzer::selectNotify(action_list_t * waiters) {
-  int numwaiters = waiters->size();
-  int random_index = random() % numwaiters;
-  action_list_t::iterator it = waiters->begin();
-  advance(it, random_index);
-  Thread *thread = model->get_thread(*it);
-  waiters->erase(it);
-  return thread;
+       int numwaiters = waiters->size();
+       int random_index = random() % numwaiters;
+       sllnode<ModelAction*> * it = waiters->begin();
+       while(random_index--)
+               it=it->getNext();
+       Thread *thread = model->get_thread(it->getVal());
+       waiters->erase(it);
+       return thread;
+}
+
+bool Fuzzer::shouldSleep(const ModelAction *sleep) {
+       return true;
+}
+
+bool Fuzzer::shouldWake(const ModelAction *sleep) {
+       struct timespec currtime;
+       clock_gettime(CLOCK_MONOTONIC, &currtime);
+       uint64_t lcurrtime = currtime.tv_sec * 1000000000 + currtime.tv_nsec;
+
+       return ((sleep->get_time()+sleep->get_value()) < lcurrtime);
 }