~ubuntu-branches/ubuntu/lucid/graphviz/lucid-security

« back to all changes in this revision

Viewing changes to tools/sfio/vthread.h

  • Committer: Bazaar Package Importer
  • Author(s): Stephen M Moraco
  • Date: 2002-02-05 18:52:12 UTC
  • Revision ID: james.westby@ubuntu.com-20020205185212-8i04c70te00rc40y
Tags: upstream-1.7.16
ImportĀ upstreamĀ versionĀ 1.7.16

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
#ifndef _VTHREAD_H
 
2
#define _VTHREAD_H      1
 
3
 
 
4
#define VTHREAD_VERSION    20001201L
 
5
 
 
6
/*      Header for the Vthread library.
 
7
**      Note that the macro vt_threaded may be defined
 
8
**      outside of vthread.h to suppress threading.
 
9
**
 
10
**      Written by Kiem-Phong Vo
 
11
*/
 
12
 
 
13
#include        <ast_common.h>
 
14
#include        <errno.h>
 
15
 
 
16
/* ast doesn't do threads yet */
 
17
#if _PACKAGE_ast && !defined(vt_threaded)
 
18
#define vt_threaded     0
 
19
#endif
 
20
 
 
21
#if !defined(vt_threaded) || (defined(vt_threaded) && vt_threaded == 1)
 
22
#define _may_use_threads        1
 
23
#else
 
24
#define _may_use_threads        0
 
25
#endif
 
26
#undef vt_threaded
 
27
 
 
28
#if _may_use_threads && !defined(vt_threaded) && _hdr_pthread
 
29
#define vt_threaded             1
 
30
#include                        <pthread.h>
 
31
typedef pthread_mutex_t         _vtmtx_t;
 
32
typedef pthread_once_t          _vtonce_t;
 
33
typedef pthread_t               _vtself_t;
 
34
typedef pthread_t               _vtid_t;
 
35
typedef pthread_attr_t          _vtattr_t;
 
36
 
 
37
#if !defined(PTHREAD_ONCE_INIT) && defined(pthread_once_init)
 
38
#define PTHREAD_ONCE_INIT       pthread_once_init
 
39
#endif
 
40
 
 
41
#endif
 
42
 
 
43
#if _may_use_threads && !defined(vt_threaded) && _WIN32
 
44
#define vt_threaded             1
 
45
#include                        <windows.h>
 
46
typedef CRITICAL_SECTION        _vtmtx_t;
 
47
typedef int                     _vtonce_t;
 
48
typedef HANDLE                  _vtself_t;
 
49
typedef DWORD                   _vtid_t;
 
50
typedef SECURITY_ATTRIBUTES     _vtattr_t;
 
51
#endif
 
52
 
 
53
#ifndef vt_threaded
 
54
#define vt_threaded             0
 
55
#endif
 
56
 
 
57
/* common attributes for various structures */
 
58
#define VT_RUNNING      000000001       /* thread is running            */
 
59
#define VT_SUSPENDED    000000002       /* thread is suspended          */
 
60
#define VT_WAITED       000000004       /* thread has been waited       */
 
61
#define VT_FREE         000010000       /* object can be freed          */
 
62
#define VT_INIT         000020000       /* object was initialized       */
 
63
#define VT_BITS         000030007       /* bits that we care about      */
 
64
 
 
65
/* directives for vtset() */
 
66
#define VT_STACK        1               /* set stack size               */
 
67
 
 
68
typedef struct _vtmutex_s       Vtmutex_t;
 
69
typedef struct _vtonce_s        Vtonce_t;
 
70
typedef struct _vthread_s       Vthread_t;
 
71
 
 
72
#ifndef EINVAL
 
73
#define EINVAL                  22
 
74
#endif
 
75
#ifndef EBUSY
 
76
#define EBUSY                   16
 
77
#endif
 
78
#ifndef EDEADLK
 
79
#define EDEADLK                 45
 
80
#endif
 
81
#ifndef EPERM
 
82
#define EPERM                   1
 
83
#endif
 
84
 
 
85
_BEGIN_EXTERNS_
 
86
 
 
87
extern Vthread_t*       vtopen _ARG_((Vthread_t*, int));
 
88
extern int              vtclose _ARG_((Vthread_t*));
 
89
extern int              vtset _ARG_((Vthread_t*, int, Void_t*));
 
90
extern int              vtrun _ARG_((Vthread_t*, void*(*)(void*), void*));
 
91
extern int              vtkill _ARG_((Vthread_t*));
 
92
extern int              vtwait _ARG_((Vthread_t*));
 
93
 
 
94
extern int              vtonce _ARG_((Vtonce_t*, void(*)() ));
 
95
 
 
96
extern Vtmutex_t*       vtmtxopen _ARG_((Vtmutex_t*, int));
 
97
extern int              vtmtxclose _ARG_((Vtmutex_t*));
 
98
extern int              vtmtxlock _ARG_((Vtmutex_t*));
 
99
extern int              vtmtxtrylock _ARG_((Vtmutex_t*));
 
100
extern int              vtmtxunlock _ARG_((Vtmutex_t*));
 
101
extern int              vtmtxclrlock _ARG_((Vtmutex_t*));
 
102
 
 
103
extern Void_t*          vtstatus _ARG_((Vthread_t*));
 
104
extern int              vterror _ARG_((Vthread_t*));
 
105
extern int              vtmtxerror _ARG_((Vtmutex_t*));
 
106
extern int              vtonceerror _ARG_((Vtonce_t*));
 
107
 
 
108
_END_EXTERNS_
 
109
 
 
110
#if vt_threaded
 
111
 
 
112
/* mutex structure */
 
113
struct _vtmutex_s
 
114
{       _vtmtx_t        lock;
 
115
        int             count;
 
116
        _vtid_t         owner;
 
117
        int             state;
 
118
        int             error;
 
119
};
 
120
 
 
121
/* structure for states of thread */
 
122
struct _vthread_s
 
123
{       _vtself_t       self;           /* self-handle          */
 
124
        _vtid_t         id;             /* thread id            */
 
125
        _vtattr_t       attrs;          /* attributes           */
 
126
        size_t          stack;          /* stack size           */
 
127
        int             state;          /* execution state      */
 
128
        int             error;          /* error status         */
 
129
        Void_t*         exit;           /* exit value           */
 
130
};
 
131
 
 
132
/* structure for exactly once execution */
 
133
struct _vtonce_s
 
134
{       int             done;
 
135
        _vtonce_t       once;
 
136
        int             error;
 
137
};
 
138
 
 
139
#if _WIN32
 
140
#define VTONCE_INITDATA         {0, 0}
 
141
#else
 
142
#define VTONCE_INITDATA         {0, PTHREAD_ONCE_INIT }
 
143
#endif
 
144
 
 
145
#define vtstatus(vt)            ((vt)->exit)
 
146
#define vterror(vt)             ((vt)->error)
 
147
#define vtmtxerror(mtx)         ((mtx)->error)
 
148
#define vtonceerror(once)       ((once)->error)
 
149
 
 
150
#endif /*vt_threaded*/
 
151
 
 
152
/* fake structures and functions */
 
153
#if !vt_threaded
 
154
struct _vtmutex_s
 
155
{       int     error;
 
156
};
 
157
struct _vtattr_s
 
158
{       int     error;
 
159
};
 
160
struct _vthread_s
 
161
{       int     error;
 
162
};
 
163
struct _vtonce_s
 
164
{       int     error;
 
165
};
 
166
 
 
167
#define VTONCE_INITDATA         {0}
 
168
 
 
169
#define vtopen(vt,flgs)         ((Vthread_t*)0)
 
170
#define vtclose(vt)             (-1)
 
171
#define vtkill(vt)              (-1)
 
172
#define vtwait(vt)              (-1)
 
173
#define vtrun(vt,fn,arg)        (-1)
 
174
 
 
175
#define vtset(vt,t,v)           (-1)
 
176
#define vtonce(on,fu)           (-1)
 
177
 
 
178
#define vtmtxopen(mtx,flgs)     ((Vtmutex_t*)0)
 
179
#define vtmtxclose(mtx)         (-1)
 
180
#define vtmtxlock(mtx)          (-1)
 
181
#define vtmtxtrylock(mtx)       (-1)
 
182
#define vtmtxunlock(mtx)        (-1)
 
183
#define vtmtxclrlock(mtx)       (-1)
 
184
 
 
185
#define vtstatus(vt)            ((Void_t*)0)
 
186
#define vterror(vt)             (0)
 
187
#define vtmtxerror(mtx)         (0)
 
188
#define vtonceerror(once)       (0)
 
189
 
 
190
#endif /*!vt_threaded*/
 
191
 
 
192
#endif /*_VTHREAD_H*/