source: CIVL/text/include/pthread.cvl@ 489c871

1.23 2.0 acw/focus-triggers main test-branch
Last change on this file since 489c871 was 0b0b558a, checked in by John Edenhofner <johneden@…>, 12 years ago

Suppressed warnings and added enums

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

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