3 #include "threads-model.h"
7 int Fuzzer::selectWrite(ModelAction *read, SnapVector<ModelAction *> * rf_set) {
8 int random_index = random() % rf_set->size();
12 Thread * Fuzzer::selectThread(int * threadlist, int numthreads) {
13 int random_index = random() % numthreads;
14 int thread = threadlist[random_index];
15 thread_id_t curr_tid = int_to_id(thread);
16 return model->get_thread(curr_tid);
19 Thread * Fuzzer::selectNotify(simple_action_list_t * waiters) {
20 int numwaiters = waiters->size();
21 int random_index = random() % numwaiters;
22 sllnode<ModelAction*> * it = waiters->begin();
25 Thread *thread = model->get_thread(it->getVal());
30 bool Fuzzer::shouldSleep(const ModelAction *sleep) {
34 bool Fuzzer::shouldWake(const ModelAction *sleep) {
35 struct timespec currtime;
36 clock_gettime(CLOCK_MONOTONIC, &currtime);
37 uint64_t lcurrtime = currtime.tv_sec * 1000000000 + currtime.tv_nsec;
39 return ((sleep->get_time()+sleep->get_value()) < lcurrtime);
42 /* Decide whether wait should spuriously fail or not */
43 bool Fuzzer::waitShouldFail(ModelAction * wait)
45 if ((random() & 1) == 0) {
46 struct timespec currtime;
47 clock_gettime(CLOCK_MONOTONIC, &currtime);
48 uint64_t lcurrtime = currtime.tv_sec * 1000000000 + currtime.tv_nsec;
50 // The time after which wait fail spuriously, in nanoseconds
51 uint64_t time = random() % 1000000;
52 wait->set_time(time + lcurrtime);
59 bool Fuzzer::waitShouldWakeUp(const ModelAction * wait)
61 struct timespec currtime;
62 clock_gettime(CLOCK_MONOTONIC, &currtime);
63 uint64_t lcurrtime = currtime.tv_sec * 1000000000 + currtime.tv_nsec;
65 return (wait->get_time() < lcurrtime);
68 bool Fuzzer::randomizeWaitTime(ModelAction * timed_wait)
70 uint64_t abstime = timed_wait->get_time();
71 struct timespec currtime;
72 clock_gettime(CLOCK_MONOTONIC, &currtime);
73 uint64_t lcurrtime = currtime.tv_sec * 1000000000 + currtime.tv_nsec;
74 if (abstime <= lcurrtime)
78 if ((random() & 1) == 0) {
79 uint64_t tmp = abstime - lcurrtime;
80 uint64_t time_to_expire = random() % tmp + lcurrtime;
81 timed_wait->set_time(time_to_expire);