source: CIVL/text/include/pthread.cvl@ 7459af4

1.23 2.0 acw/focus-triggers main test-branch
Last change on this file since 7459af4 was 89bc970, checked in by John Edenhofner <johneden@…>, 12 years ago

Updated pthread_barrier_t and made an example to begin to test it

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

  • Property mode set to 100644
File size: 4.9 KB
Line 
1#ifdef __PTHREAD_CVL__
2#else
3#define __PTHREAD_CVL__
4#include <sched.cvl>
5
6
7//Mutex types
8enum{
9PTHREAD_MUTEX_NORMAL,
10PTHREAD_MUTEX_RECURSIVE,
11PTHREAD_MUTEX_ERRORCHECK
12};
13
14enum{
15PTHREAD_MUTEX_STALLED,
16PTHREAD_MUTEX_ROBUST
17};
18
19enum{
20PTHREAD_CREATE_JOINABLE,
21PTHREAD_CREATE_DETACHED
22};
23
24enum{
25PTHREAD_SCOPE_SYSTEM,
26PTHREAD_SCOPE_PROCESS
27};
28
29enum{
30PTHREAD_INHERIT_SCHED,
31PTHREAD_EXPLICIT_SCHED
32};
33
34enum{
35PTHREAD_PROCESS_SHARED,
36PTHREAD_PROCESS_PRIVATE,
37};
38
39enum{
40PTHREAD_BARRIER_SERIAL_THREAD
41};
42
43//Mutex initializer
44#define __LOCK_INITIALIZER 0
45#define PTHREAD_MUTEX_INITIALIZER {0,0,0,PTHREAD_MUTEX_NORMAL,__LOCK_INITIALIZER}
46#define PTHREAD_COND_INITIALIZER {__LOCK_INITIALIZER,0}
47
48//Error definitions
49enum{
50EINVAL, //Designates an invalid value
51ENOTSUP,
52EOWNERDEAD, //Designates the termination of the owning thread
53EBUSY, //Mutex is already locked
54EDEADLK, //If mutex type is errorcheck and already owns the mutex
55EPERM, //If mutex is robust or errorcheck and does not own the mutex
56ERSCH
57};
58
59// In process of implementing
60
61typedef struct {
62 int pshared;
63} pthread_barrierattr_t;
64
65typedef struct {
66 pthread_barrierattr_t attr;
67 int count;
68 $gbarrier barr;
69} pthread_barrier_t;
70
71typedef struct {
72 $proc owner;
73 _Bool lock;
74 int pshared;
75}pthread_spinlock_t;
76/*
77typedef struct {
78 int pshared;
79 clockid_t clock_id;
80}pthread_condattr_t;
81*/
82
83/* Implemented struct definitions */
84
85/* pthread_attr_t struct definition
86 Description: This struct corresponds to the pthread_attr_t which is the attribute of a pthread_t. It's fields
87 define the way the pthread_t is able to interact (join/detach), (memory capacity), (scope) etc.
88
89 Fields:
90 int detachstate: Defines a threads ability to join with two values: PTHREAD_CREATE_DETACHED and PTHREAD_CREATE_JOINABLE
91 int inheritsched: The inheritance scheduling policy of the thread
92 int contentionscope: Defines the contention scope of the thread
93 int schedpolicy: Determines the scheduling policy of the thread
94
95*/
96
97typedef struct {
98 int detachstate;
99 int inheritsched;
100 int contentionscope;
101 int schedpolicy;
102 //sched_param param;
103} pthread_attr_t;
104
105/* pthread_mutexattr_t struct definition
106 Description: The pthread_mutexattr_t defines multiple attributes of a mutex and controls its interactions with threads
107 Fields: robust: defines the robustness of the mutex; if robust and the owning thread terminates, it will notify the
108 next thread of this to prevent deadlocks and other errors
109 pshared: defines the process shared element of the thread and which processes can interact with the mutex
110 protocol: defines the priority protocol of the mutex and which threads may interact first
111 type: defines the type of the mutex as either PTHREAD_MUTEX_DEFAULT/NORMAL, PTHREAD_MUTEX_ERRORCHECK, or
112 PTHREAD_MUTEX_RECURSIVE, each explained in pthread_mutex_lock below
113 prioceiling: defines the lowest priority the mutex's critical section can be at
114*/
115
116typedef struct {
117 int robust;
118 int pshared;
119 int protocol;
120 int type;
121 int prioceiling;
122}pthread_mutexattr_t;
123
124/* pthread_mutex_t struct definition
125 Description: The pthread_mutex_t is a locking mechanism for threads to interact with in order to control the scheduling
126 of the threads. It can be locked, which allows for blocking of other threads waiting on the mutex and unlocked, allowing
127 access. It has a pthread_mutexattr_t which defines its behavior.
128 Fields: count - used for recursive mutex, incremented when locked, decremented when unlocked, mutex released when count is 0
129 owner - current process owner of the mutex
130 lock - int of 0 or 1, respectively 0 if unlocked, 1 if locked
131 prioceiling - allows locking without adherence to the priority ceiling
132 attr - see above
133*/
134
135typedef struct {
136 int count;
137 $proc owner;
138 int lock;
139 int prioceiling;
140 pthread_mutexattr_t attr;
141} pthread_mutex_t;
142
143
144/* pthread_cond_t struct definition
145 Description: The pthread_cond_t is another locking mechanism which interacts with the mutex variable. When
146 the mutex is locked, the condition can be accessed, leading the accessing thread to unlock it, and sleep
147 until the signal is given
148 Fields: proccount - specifies the number of processes/threads still waiting on this condition variable
149 signal - Boolean value stating whether the condition is satisfied (indicated by 1) or not (0)
150*/
151
152typedef struct {
153 int proccount;
154 _Bool signal;
155} pthread_cond_t;
156
157/* pthread_t struct definition
158 Description: The pthread_t is a struct containing a $proc variable as well as a thread attribute which defines
159 its interactions with other threads. It encapsulates the $proc and allows attributes to apply to it.
160 Fields: thr: the $proc variable that is the heart of the thread
161 attr: see above
162*/
163
164typedef struct {
165 $proc thr;
166 const pthread_attr_t attr;
167 _Bool terminated;
168} pthread_t;
169
170typedef struct __pthread_pool_t {
171 pthread_t** threads;
172 int len;
173} __pthread_pool_t;
174
175#endif
176
Note: See TracBrowser for help on using the repository browser.