small changes
[c11tester.git] / fuzzer.cc
index 9ad61c3c5cddbc96073e85c15e8dd05f46bffadb..e102d9c34431a13dea089d9437857640e2691cfd 100644 (file)
--- a/fuzzer.cc
+++ b/fuzzer.cc
@@ -2,25 +2,44 @@
 #include <stdlib.h>
 #include "threads-model.h"
 #include "model.h"
+#include "action.h"
 
 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) {
+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) {
+Thread * Fuzzer::selectNotify(simple_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);
+       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);
+}
+
+bool Fuzzer::shouldWait(const ModelAction * act)
+{
+       return true;
+}