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

1.23 2.0 main test-branch
Last change on this file since b18cc45 was e182ee04, checked in by John Edenhofner <johneden@…>, 12 years ago

Added basic scheduling header, modified pthread_mutex_lock as well as mutliple other methods

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

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