From 805ebd24556eda8ae7183ee3f518148e86799ac1 Mon Sep 17 00:00:00 2001 From: bdemsky Date: Tue, 4 Jun 2019 23:01:15 -0700 Subject: [PATCH] make some changes with hacks --- action.h | 2 +- clockvector.cc | 2 ++ execution.cc | 10 ++++++++-- execution.h | 6 +++--- include/memoryorder.h | 4 +--- include/{pthread.h => mypthread.h} | 25 ++----------------------- libthreads.cc | 3 ++- pthread.cc | 5 +++-- threads-model.h | 2 +- 9 files changed, 23 insertions(+), 36 deletions(-) rename include/{pthread.h => mypthread.h} (88%) diff --git a/action.h b/action.h index de5bca90..e78bb9c5 100644 --- a/action.h +++ b/action.h @@ -11,7 +11,7 @@ #include "mymemory.h" #include "memoryorder.h" #include "modeltypes.h" -#include "pthread.h" +#include "mypthread.h" #include "classlist.h" namespace cdsc { diff --git a/clockvector.cc b/clockvector.cc index 5f068e90..467a27e9 100644 --- a/clockvector.cc +++ b/clockvector.cc @@ -2,10 +2,12 @@ #include #include "action.h" + #include "clockvector.h" #include "common.h" #include "threads-model.h" + /** * Constructs a new ClockVector, given a parent ClockVector and a first * ModelAction. This constructor can assign appropriate default settings if no diff --git a/execution.cc b/execution.cc index 7d38eb43..dabf5509 100644 --- a/execution.cc +++ b/execution.cc @@ -495,7 +495,7 @@ bool ModelExecution::process_thread_action(ModelAction *curr) break; } case PTHREAD_CREATE: { - (*(pthread_t *)curr->get_location()) = pthread_counter++; + (*(uint32_t *)curr->get_location()) = pthread_counter++; struct pthread_params *params = (struct pthread_params *)curr->get_value(); Thread *th = new Thread(get_next_id(), NULL, params->func, params->arg, get_thread(curr)); @@ -1522,7 +1522,13 @@ Thread * ModelExecution::get_thread(const ModelAction *act) const * @return A Thread reference */ Thread * ModelExecution::get_pthread(pthread_t pid) { - if (pid < pthread_counter + 1) return pthread_map[pid]; + union { + pthread_t p; + uint32_t v; + } x; + x.p = pid; + uint32_t thread_id = x.v; + if (thread_id < pthread_counter + 1) return pthread_map[thread_id]; else return NULL; } diff --git a/execution.h b/execution.h index e15270f4..d13cc721 100644 --- a/execution.h +++ b/execution.h @@ -14,7 +14,7 @@ #include "modeltypes.h" #include "stl-model.h" #include "params.h" - +#include "mypthread.h" #include "mutex.h" #include #include "classlist.h" @@ -70,7 +70,7 @@ public: Thread * get_thread(thread_id_t tid) const; Thread * get_thread(const ModelAction *act) const; - pthread_t get_pthread_counter() { return pthread_counter; } + uint32_t get_pthread_counter() { return pthread_counter; } void incr_pthread_counter() { pthread_counter++; } Thread * get_pthread(pthread_t pid); @@ -156,7 +156,7 @@ private: action_list_t action_trace; SnapVector thread_map; SnapVector pthread_map; - pthread_t pthread_counter; + uint32_t pthread_counter; /** Per-object list of actions. Maps an object (i.e., memory location) * to a trace of all actions performed on the object. */ diff --git a/include/memoryorder.h b/include/memoryorder.h index 704d15e7..ca496f1a 100644 --- a/include/memoryorder.h +++ b/include/memoryorder.h @@ -12,13 +12,11 @@ namespace std { #include #endif - typedef enum memory_order { memory_order_relaxed, memory_order_consume, memory_order_acquire, memory_order_release, memory_order_acq_rel, memory_order_seq_cst } memory_order; - - + #ifdef __cplusplus } #endif diff --git a/include/pthread.h b/include/mypthread.h similarity index 88% rename from include/pthread.h rename to include/mypthread.h index 8e0a6908..b697bde2 100644 --- a/include/pthread.h +++ b/include/mypthread.h @@ -3,33 +3,13 @@ * @brief C11 pthread.h interface header */ #ifndef PTHREAD_H -#define PTHREAD_H 1 +#define PTHREAD_H #include #include -#include +//#include #include -/* Mutex types. */ -enum -{ - PTHREAD_MUTEX_TIMED_NP, - PTHREAD_MUTEX_RECURSIVE_NP, - PTHREAD_MUTEX_ERRORCHECK_NP, - PTHREAD_MUTEX_ADAPTIVE_NP -#if defined __USE_UNIX98 || defined __USE_XOPEN2K8 - , - PTHREAD_MUTEX_NORMAL = PTHREAD_MUTEX_TIMED_NP, - PTHREAD_MUTEX_RECURSIVE = PTHREAD_MUTEX_RECURSIVE_NP, - PTHREAD_MUTEX_ERRORCHECK = PTHREAD_MUTEX_ERRORCHECK_NP, - PTHREAD_MUTEX_DEFAULT = PTHREAD_MUTEX_NORMAL -#endif -#ifdef __USE_GNU - /* For compatibility. */ - , PTHREAD_MUTEX_FAST_NP = PTHREAD_MUTEX_TIMED_NP -#endif -}; - typedef void *(*pthread_start_t)(void *); struct pthread_params { @@ -58,7 +38,6 @@ int pthread_cond_timedwait(pthread_cond_t *p_cond, pthread_mutex_t *p_mutex, const struct timespec *abstime); int pthread_cond_signal(pthread_cond_t *); -void pthread_cleanup_push(void (*routine)(void*), void *arg ); int user_main(int, char**); diff --git a/libthreads.cc b/libthreads.cc index 75d19107..5ff106c8 100644 --- a/libthreads.cc +++ b/libthreads.cc @@ -1,8 +1,9 @@ -#include +#include "threads.h" #include "common.h" #include "threads-model.h" #include "action.h" + /* global "model" object */ #include "model.h" diff --git a/pthread.cc b/pthread.cc index 3f0a1e4f..87dc2065 100644 --- a/pthread.cc +++ b/pthread.cc @@ -1,7 +1,7 @@ #include "common.h" #include "threads-model.h" #include "action.h" -#include "pthread.h" +#include "mypthread.h" #include "snapshot-interface.h" #include "datarace.h" @@ -44,6 +44,7 @@ int pthread_join(pthread_t t, void **value_ptr) { void pthread_exit(void *value_ptr) { Thread * th = thread_current(); model->switch_to_master(new ModelAction(THREAD_FINISH, std::memory_order_seq_cst, th)); + while(1) ; //make warning goaway } int pthread_mutex_init(pthread_mutex_t *p_mutex, const pthread_mutexattr_t *) { @@ -121,7 +122,7 @@ int pthread_mutex_timedlock (pthread_mutex_t *__restrict p_mutex, pthread_t pthread_self() { Thread* th = model->get_current_thread(); - return th->get_id(); + return (pthread_t)th->get_id(); } int pthread_key_delete(pthread_key_t) { diff --git a/threads-model.h b/threads-model.h index 8ba9d9b6..c6e3a3af 100644 --- a/threads-model.h +++ b/threads-model.h @@ -8,7 +8,7 @@ #include #include "mymemory.h" -#include +#include "threads.h" #include "modeltypes.h" #include "stl-model.h" #include "context.h" -- 2.34.1