X-Git-Url: http://demsky.eecs.uci.edu/git/?a=blobdiff_plain;f=pthread.cc;h=f5ce1bcf514e23c7a3e3b4e3f8facd82fa8b6ce2;hb=c7a5091afba87a67423c0797fa001914ce9e2ff4;hp=e453f1b27e45b2188c73231fbac3d436cd15ac6a;hpb=7bba6b355f7b2250aed59de4b9d20f36c89a3eb4;p=c11tester.git diff --git a/pthread.cc b/pthread.cc index e453f1b2..f5ce1bcf 100644 --- a/pthread.cc +++ b/pthread.cc @@ -64,13 +64,18 @@ void pthread_exit(void *value_ptr) { real_pthread_exit(NULL); } -int pthread_mutex_init(pthread_mutex_t *p_mutex, const pthread_mutexattr_t *) { +int pthread_mutex_init(pthread_mutex_t *p_mutex, const pthread_mutexattr_t * attr) { if (!model) { snapshot_system_init(10000, 1024, 1024, 40000); model = new ModelChecker(); model->startChecker(); } - cdsc::snapmutex *m = new cdsc::snapmutex(); + + int mutex_type = PTHREAD_MUTEX_DEFAULT; + if (attr != NULL) + pthread_mutexattr_gettype(attr, &mutex_type); + + cdsc::snapmutex *m = new cdsc::snapmutex(mutex_type); ModelExecution *execution = model->get_execution(); execution->getMutexMap()->put(p_mutex, m); @@ -160,6 +165,12 @@ int pthread_mutex_timedlock (pthread_mutex_t *__restrict p_mutex, } pthread_t pthread_self() { + if (!model) { + snapshot_system_init(10000, 1024, 1024, 40000); + model = new ModelChecker(); + model->startChecker(); + } + Thread* th = model->get_current_thread(); return (pthread_t)th->get_id(); } @@ -244,3 +255,37 @@ int pthread_cond_destroy(pthread_cond_t *p_cond) { } return 0; } + +/* https://github.com/lattera/glibc/blob/master/nptl/pthread_getattr_np.c */ +int pthread_getattr_np(pthread_t t, pthread_attr_t *attr) +{ + ModelExecution *execution = model->get_execution(); + Thread *th = execution->get_pthread(t); + + struct pthread_attr *iattr = (struct pthread_attr *) attr; + + /* The sizes are subject to alignment. */ + if (th != NULL) { +#if _STACK_GROWS_DOWN + ASSERT(false); +#else + iattr->stackaddr = (char *) th->get_stack_addr(); +#endif + + } else { + ASSERT(false); + } + + return 0; +} + +int pthread_setname_np(pthread_t t, const char *name) +{ + ModelExecution *execution = model->get_execution(); + Thread *th = execution->get_pthread(t); + + if (th != NULL) + return 0; + + return 1; +}