source: CIVL/text/include/pthread.cvl@ e1e1717

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

Added preprocessor macros as guards

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

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