Modified the implementation of usleep and make ModelExecution process "THREAD SLEEP...
[c11tester.git] / pthread.cc
index 715f6f6..d6067eb 100644 (file)
 /* global "model" object */
 #include "model.h"
 #include "execution.h"
-extern "C" {
-int nanosleep(const struct timespec *rqtp, struct timespec *rmtp);
-}
-
-int nanosleep(const struct timespec *rqtp, struct timespec *rmtp) {
-       if (model) {
-               uint64_t time = rqtp->tv_sec * 1000000000 + rqtp->tv_nsec;
-               struct timespec currtime;
-               clock_gettime(CLOCK_MONOTONIC, &currtime);
-               uint64_t lcurrtime = currtime.tv_sec * 1000000000 + currtime.tv_nsec;
-               model->switch_to_master(new ModelAction(THREAD_SLEEP, std::memory_order_seq_cst, time, lcurrtime));
-               if (rmtp != NULL) {
-                       clock_gettime(CLOCK_MONOTONIC, &currtime);
-                       uint64_t lendtime = currtime.tv_sec * 1000000000 + currtime.tv_nsec;
-                       uint64_t elapsed = lendtime - lcurrtime;
-                       rmtp->tv_sec = elapsed / 1000000000;
-                       rmtp->tv_nsec = elapsed - rmtp->tv_sec * 1000000000;
-               }
-       }
-       return 0;
-}
+#include <errno.h>
 
 int pthread_create(pthread_t *t, const pthread_attr_t * attr,
         pthread_start_t start_routine, void * arg) {
@@ -169,11 +149,10 @@ int pthread_mutex_timedlock (pthread_mutex_t *__restrict p_mutex,
 
        if (m != NULL) {
                m->lock();
-       } else {
-               return 1;
+               return 0;
        }
 
-       return 0;
+       return 1;
 }
 
 pthread_t pthread_self() {