source: CIVL/text/include/pthread.h@ 325d439

1.23 2.0 main test-branch
Last change on this file since 325d439 was 8a9124e, checked in by Manchun Zheng <zmanchun@…>, 12 years ago

added a simple test for MPI Translation in CIVL.

git-svn-id: svn://vsl.cis.udel.edu/civl/trunk@860 fb995dde-84ed-4084-dfe6-e5aef3e2452c

  • Property mode set to 100755
File size: 1.4 KB
Line 
1#ifdef __PTHREAD__
2#else
3#define __PTHREAD__
4
5#include<pthread-common.h>
6#include <civlc.h>
7
8void pthread_cond_init(pthread_cond_t *cond, int kind){
9 cond->proccount = 0;
10 cond->signal = $false;
11}
12
13//Initializes mutex as unlocked and kind as defined by int m
14void pthread_mutex_init(pthread_mutex_t *mutex, int m){
15 mutex->kind = m;
16 mutex->lock = 0;
17}
18
19int pthread_mutex_lock(pthread_mutex_t *mutex) {
20 $when(mutex->lock == 0) mutex->lock = 1;
21 mutex->owner = $self;
22 return 0;
23}
24
25
26int pthread_mutex_unlock(pthread_mutex_t *mutex) {
27 mutex->lock = 0;
28 return 0;
29}
30
31int pthread_cond_wait(pthread_cond_t *cond, pthread_mutex_t *mutex){
32 if(mutex->owner != $self)
33 {
34 printf("Mutex not owned by thread");
35 $assert($false);
36 return 0;
37 }
38 cond->proccount++;
39 pthread_mutex_unlock(mutex);
40 $when(cond->signal == $true);
41 cond->signal = $false;
42 --cond->proccount;
43 $when(mutex->lock == 0){pthread_mutex_lock(mutex);}
44}
45
46int pthread_cond_signal(pthread_cond_t *cond){
47 cond->signal = $true;
48}
49
50int pthread_cond_broadcast(pthread_cond_t *cond){
51 while(cond->proccount > 0){
52 cond->signal = $true;
53 }
54}
55
56int pthread_create(pthread_t *thread, const pthread_attr_t *attr,
57 void *(*start_routine)(void*), void *arg){
58 *thread = $spawn start_routine(arg);
59 return 0;
60}
61
62int pthread_join(pthread_t thread, void **value_ptr) {
63 $wait(thread);
64 return 0;
65}
66#endif
Note: See TracBrowser for help on using the repository browser.