implement usleep and sleep system calls as no operation which returns control to...
authorweiyu <weiyuluo1232@gmail.com>
Mon, 17 Jun 2019 20:08:01 +0000 (13:08 -0700)
committerweiyu <weiyuluo1232@gmail.com>
Mon, 17 Jun 2019 20:08:01 +0000 (13:08 -0700)
Makefile
action.cc
action.h
execution.cc
sleeps.cc [new file with mode: 0644]

index b0d946d..7c73b9b 100644 (file)
--- a/Makefile
+++ b/Makefile
@@ -4,7 +4,8 @@ OBJECTS := libthreads.o schedule.o model.o threads.o librace.o action.o \
           nodestack.o clockvector.o main.o snapshot-interface.o cyclegraph.o \
           datarace.o impatomic.o cmodelint.o \
           snapshot.o malloc.o mymemory.o common.o mutex.o conditionvariable.o \
-          context.o execution.o libannotate.o plugins.o pthread.o futex.o fuzzer.o
+          context.o execution.o libannotate.o plugins.o pthread.o futex.o fuzzer.o \
+          sleeps.o
 
 CPPFLAGS += -Iinclude -I.
 LDFLAGS := -ldl -lrt -rdynamic
index af84907..df44af1 100644 (file)
--- a/action.cc
+++ b/action.cc
@@ -45,7 +45,7 @@ ModelAction::ModelAction(action_type_t type, memory_order order, void *loc,
        seq_number(ACTION_INITIAL_CLOCK)
 {
        /* References to NULL atomic variables can end up here */
-       ASSERT(loc || type == ATOMIC_FENCE);
+       ASSERT(loc || type == ATOMIC_FENCE || type == NOOP);
 
        Thread *t = thread ? thread : thread_current();
        this->tid = t->get_id();
@@ -117,7 +117,7 @@ ModelAction::ModelAction(action_type_t type, const char * position, memory_order
 
        Thread *t = thread ? thread : thread_current();
        this->tid = t->get_id();
-       model_print("position: %s\n", position);
+       // model_print("position: %s\n", position);
 }
 
 
index e65b8db..1797e61 100644 (file)
--- a/action.h
+++ b/action.h
@@ -70,7 +70,7 @@ typedef enum action_type {
        ATOMIC_NOTIFY_ALL,      // < A notify all action
        ATOMIC_WAIT,    // < A wait action
        ATOMIC_ANNOTATION,      // < An annotation action to pass information to a trace analysis
-       NOOP
+       NOOP            // no operation, which returns control to scheduler
 } action_type_t;
 
 
index 213b260..4a351a9 100644 (file)
@@ -682,7 +682,7 @@ ModelAction * ModelExecution::check_current_action(ModelAction *curr)
        wake_up_sleeping_actions(curr);
 
        /* Add the action to lists before any other model-checking tasks */
-       if (!second_part_of_rmw)
+       if (!second_part_of_rmw && curr->get_type() != NOOP)
                add_action_to_lists(curr);
 
        SnapVector<ModelAction *> * rf_set = NULL;
@@ -1106,7 +1106,7 @@ bool ModelExecution::release_seq_heads(const ModelAction *rf, rel_heads_list_t *
  * @see ModelExecution::release_seq_heads
  */
 void ModelExecution::get_release_seq_heads(ModelAction *acquire,
-                                                                                                                                                                        ModelAction *read, rel_heads_list_t *release_heads)
+                ModelAction *read, rel_heads_list_t *release_heads)
 {
        const ModelAction *rf = read->get_reads_from();
 
diff --git a/sleeps.cc b/sleeps.cc
new file mode 100644 (file)
index 0000000..0528374
--- /dev/null
+++ b/sleeps.cc
@@ -0,0 +1,26 @@
+#include <time.h>
+#include <unistd.h>
+
+#include "action.h"
+#include "model.h"
+
+unsigned int __sleep (unsigned int seconds)
+{
+       model->switch_to_master(
+               new ModelAction(NOOP, std::memory_order_seq_cst, NULL)
+       );
+       return 0;
+}
+
+unsigned int sleep(unsigned int seconds)
+{
+       return __sleep(seconds);
+}
+
+int usleep (useconds_t useconds)
+{
+       model->switch_to_master(
+               new ModelAction(NOOP, std::memory_order_seq_cst, NULL)
+       );
+       return 0;
+}