Do not unset FuncInst locations when new executions start; check if execution numbers...
[c11tester.git] / fuzzer.cc
index 62097b216f4997ea1574dd513b74099b0f569b8e..5b5be9ff4441942fbfd22461d13b0c3788a9c7d6 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"
 
-ModelAction * Fuzzer::selectWrite(ModelAction *read, ModelVector<ModelAction *> * rf_set) {
-  int random_index = random() % rf_set->size();
-  return (*rf_set)[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);
 }