Subversion Repositories Kolibri OS

Rev

Rev 1693 | Go to most recent revision | Only display areas with differences | Regard whitespace | Details | Blame | Last modification | View Log | RSS feed

Rev 1693 Rev 2168
1
/* unified sys/types.h: 
1
/* unified sys/types.h: 
2
   start with sef's sysvi386 version.
2
   start with sef's sysvi386 version.
3
   merge go32 version -- a few ifdefs.
3
   merge go32 version -- a few ifdefs.
4
   h8300hms, h8300xray, and sysvnecv70 disagree on the following types:
4
   h8300hms, h8300xray, and sysvnecv70 disagree on the following types:
5
 
5
 
6
   typedef int gid_t;
6
   typedef int gid_t;
7
   typedef int uid_t;
7
   typedef int uid_t;
8
   typedef int dev_t;
8
   typedef int dev_t;
9
   typedef int ino_t;
9
   typedef int ino_t;
10
   typedef int mode_t;
10
   typedef int mode_t;
11
   typedef int caddr_t;
11
   typedef int caddr_t;
12
 
12
 
13
   however, these aren't "reasonable" values, the sysvi386 ones make far 
13
   however, these aren't "reasonable" values, the sysvi386 ones make far 
14
   more sense, and should work sufficiently well (in particular, h8300 
14
   more sense, and should work sufficiently well (in particular, h8300 
15
   doesn't have a stat, and the necv70 doesn't matter.) -- eichin
15
   doesn't have a stat, and the necv70 doesn't matter.) -- eichin
16
 */
16
 */
17
 
17
 
18
#ifndef _SYS_TYPES_H
18
#ifndef _SYS_TYPES_H
19
 
19
 
20
#include <_ansi.h>
20
#include <_ansi.h>
21
 
21
 
22
#ifndef __INTTYPES_DEFINED__
22
#ifndef __INTTYPES_DEFINED__
23
#define __INTTYPES_DEFINED__
23
#define __INTTYPES_DEFINED__
24
 
24
 
25
#include 
25
#include 
26
 
26
 
27
#if defined(__rtems__) || defined(__XMK__)
27
#if defined(__rtems__) || defined(__XMK__)
28
/*
28
/*
29
 *  The following section is RTEMS specific and is needed to more
29
 *  The following section is RTEMS specific and is needed to more
30
 *  closely match the types defined in the BSD sys/types.h.
30
 *  closely match the types defined in the BSD sys/types.h.
31
 *  This is needed to let the RTEMS/BSD TCP/IP stack compile.
31
 *  This is needed to let the RTEMS/BSD TCP/IP stack compile.
32
 */
32
 */
33
 
33
 
34
/* deprecated */
34
/* deprecated */
35
#if ___int8_t_defined
35
#if ___int8_t_defined
36
typedef __uint8_t	u_int8_t;
36
typedef __uint8_t	u_int8_t;
37
#endif
37
#endif
38
#if ___int16_t_defined
38
#if ___int16_t_defined
39
typedef __uint16_t	u_int16_t;
39
typedef __uint16_t	u_int16_t;
40
#endif 
40
#endif 
41
#if ___int32_t_defined
41
#if ___int32_t_defined
42
typedef __uint32_t	u_int32_t;
42
typedef __uint32_t	u_int32_t;
43
#endif
43
#endif
44
 
44
 
45
#if ___int64_t_defined
45
#if ___int64_t_defined
46
typedef __uint64_t	u_int64_t;
46
typedef __uint64_t	u_int64_t;
47
 
47
 
48
/* deprecated */
48
/* deprecated */
49
typedef	__uint64_t	u_quad_t;
49
typedef	__uint64_t	u_quad_t;
50
typedef	__int64_t	quad_t;
50
typedef	__int64_t	quad_t;
51
typedef	quad_t *	qaddr_t;
51
typedef	quad_t *	qaddr_t;
52
#endif
52
#endif
53
 
53
 
54
#endif
54
#endif
55
 
55
 
56
#endif /* ! __INTTYPES_DEFINED */
56
#endif /* ! __INTTYPES_DEFINED */
57
 
57
 
58
#ifndef __need_inttypes
58
#ifndef __need_inttypes
59
 
59
 
60
#define _SYS_TYPES_H
60
#define _SYS_TYPES_H
61
#include 
61
#include 
62
 
62
 
63
#ifdef __i386__
63
#ifdef __i386__
64
#if defined (GO32) || defined (__MSDOS__)
64
#if defined (GO32) || defined (__MSDOS__)
65
#define __MS_types__
65
#define __MS_types__
66
#endif
66
#endif
67
#endif
67
#endif
68
 
68
 
69
# include 
69
# include 
70
# include 
70
# include 
71
 
71
 
72
/* To ensure the stat struct's layout doesn't change when sizeof(int), etc.
72
/* To ensure the stat struct's layout doesn't change when sizeof(int), etc.
73
   changes, we assume sizeof short and long never change and have all types
73
   changes, we assume sizeof short and long never change and have all types
74
   used to define struct stat use them and not int where possible.
74
   used to define struct stat use them and not int where possible.
75
   Where not possible, _ST_INTxx are used.  It would be preferable to not have
75
   Where not possible, _ST_INTxx are used.  It would be preferable to not have
76
   such assumptions, but until the extra fluff is necessary, it's avoided.
76
   such assumptions, but until the extra fluff is necessary, it's avoided.
77
   No 64 bit targets use stat yet.  What to do about them is postponed
77
   No 64 bit targets use stat yet.  What to do about them is postponed
78
   until necessary.  */
78
   until necessary.  */
79
#ifdef __GNUC__
79
#ifdef __GNUC__
80
#define _ST_INT32 __attribute__ ((__mode__ (__SI__)))
80
#define _ST_INT32 __attribute__ ((__mode__ (__SI__)))
81
#else
81
#else
82
#define _ST_INT32
82
#define _ST_INT32
83
#endif
83
#endif
84
 
84
 
85
# ifndef	_POSIX_SOURCE
85
# ifndef	_POSIX_SOURCE
86
 
86
 
87
#  define	physadr		physadr_t
87
#  define	physadr		physadr_t
88
#  define	quad		quad_t
88
#  define	quad		quad_t
89
 
89
 
90
#ifndef _BSDTYPES_DEFINED
90
#ifndef _BSDTYPES_DEFINED
91
/* also defined in mingw/gmon.h and in w32api/winsock[2].h */
91
/* also defined in mingw/gmon.h and in w32api/winsock[2].h */
92
typedef	unsigned char	u_char;
92
typedef	unsigned char	u_char;
93
typedef	unsigned short	u_short;
93
typedef	unsigned short	u_short;
94
typedef	unsigned int	u_int;
94
typedef	unsigned int	u_int;
95
typedef	unsigned long	u_long;
95
typedef	unsigned long	u_long;
96
#define _BSDTYPES_DEFINED
96
#define _BSDTYPES_DEFINED
97
#endif
97
#endif
98
 
98
 
99
typedef	unsigned short	ushort;		/* System V compatibility */
99
typedef	unsigned short	ushort;		/* System V compatibility */
100
typedef	unsigned int	uint;		/* System V compatibility */
100
typedef	unsigned int	uint;		/* System V compatibility */
101
# endif	/*!_POSIX_SOURCE */
101
# endif	/*!_POSIX_SOURCE */
102
 
102
 
103
#ifndef __clock_t_defined
103
#ifndef __clock_t_defined
104
typedef _CLOCK_T_ clock_t;
104
typedef _CLOCK_T_ clock_t;
105
#define __clock_t_defined
105
#define __clock_t_defined
106
#endif
106
#endif
107
 
107
 
108
#ifndef __time_t_defined
108
#ifndef __time_t_defined
109
typedef _TIME_T_ time_t;
109
typedef _TIME_T_ time_t;
110
#define __time_t_defined
110
#define __time_t_defined
111
 
111
 
112
/* Time Value Specification Structures, P1003.1b-1993, p. 261 */
112
/* Time Value Specification Structures, P1003.1b-1993, p. 261 */
113
 
113
 
114
struct timespec {
114
struct timespec {
115
  time_t  tv_sec;   /* Seconds */
115
  time_t  tv_sec;   /* Seconds */
116
  long    tv_nsec;  /* Nanoseconds */
116
  long    tv_nsec;  /* Nanoseconds */
117
};
117
};
118
 
118
 
119
struct itimerspec {
119
struct itimerspec {
120
  struct timespec  it_interval;  /* Timer period */
120
  struct timespec  it_interval;  /* Timer period */
121
  struct timespec  it_value;     /* Timer expiration */
121
  struct timespec  it_value;     /* Timer expiration */
122
};
122
};
123
#endif
123
#endif
124
 
124
 
125
typedef	long	daddr_t;
125
typedef	long	daddr_t;
126
typedef	char *	caddr_t;
126
typedef	char *	caddr_t;
127
 
127
 
128
#ifndef __CYGWIN__
128
#ifndef __CYGWIN__
129
#if defined(__MS_types__) || defined(__rtems__) || \
129
#if defined(__MS_types__) || defined(__rtems__) || \
130
    defined(__sparc__) || defined(__SPU__)
130
    defined(__sparc__) || defined(__SPU__)
131
typedef	unsigned long	ino_t;
131
typedef	unsigned long	ino_t;
132
#else
132
#else
133
typedef	unsigned short	ino_t;
133
typedef	unsigned short	ino_t;
134
#endif
134
#endif
135
#endif /*__CYGWIN__*/
135
#endif /*__CYGWIN__*/
136
 
136
 
137
#ifdef __MS_types__
137
#ifdef __MS_types__
138
typedef unsigned long vm_offset_t;
138
typedef unsigned long vm_offset_t;
139
typedef unsigned long vm_size_t;
139
typedef unsigned long vm_size_t;
140
 
140
 
141
#define __BIT_TYPES_DEFINED__
141
#define __BIT_TYPES_DEFINED__
142
 
142
 
143
typedef signed char int8_t;
143
typedef signed char int8_t;
144
typedef unsigned char u_int8_t;
144
typedef unsigned char u_int8_t;
145
typedef short int16_t;
145
typedef short int16_t;
146
typedef unsigned short u_int16_t;
146
typedef unsigned short u_int16_t;
147
typedef int int32_t;
147
typedef int int32_t;
148
typedef unsigned int u_int32_t;
148
typedef unsigned int u_int32_t;
149
typedef long long int64_t;
149
typedef long long int64_t;
150
typedef unsigned long long u_int64_t;
150
typedef unsigned long long u_int64_t;
151
typedef int32_t register_t;
151
typedef int32_t register_t;
152
#endif /* __MS_types__ */
152
#endif /* __MS_types__ */
153
 
153
 
154
/*
154
/*
155
 * All these should be machine specific - right now they are all broken.
155
 * All these should be machine specific - right now they are all broken.
156
 * However, for all of Cygnus' embedded targets, we want them to all be
156
 * However, for all of Cygnus' embedded targets, we want them to all be
157
 * the same.  Otherwise things like sizeof (struct stat) might depend on
157
 * the same.  Otherwise things like sizeof (struct stat) might depend on
158
 * how the file was compiled (e.g. -mint16 vs -mint32, etc.).
158
 * how the file was compiled (e.g. -mint16 vs -mint32, etc.).
159
 */
159
 */
160
 
160
 
161
#ifndef __CYGWIN__	/* which defines these types in it's own types.h. */
161
#ifndef __CYGWIN__	/* which defines these types in it's own types.h. */
162
typedef _off_t	off_t;
162
typedef _off_t	off_t;
163
typedef __dev_t dev_t;
163
typedef __dev_t dev_t;
164
typedef __uid_t uid_t;
164
typedef __uid_t uid_t;
165
typedef __gid_t gid_t;
165
typedef __gid_t gid_t;
166
#endif
166
#endif
167
 
167
 
168
#if defined(__XMK__)
168
#if defined(__XMK__)
169
typedef signed char pid_t;
169
typedef signed char pid_t;
170
#else
170
#else
171
typedef int pid_t;
171
typedef int pid_t;
172
#endif
172
#endif
-
 
173
 
-
 
174
#if defined(__rtems__)
-
 
175
typedef _mode_t mode_t;
-
 
176
#endif
173
 
177
 
174
#ifndef __CYGWIN__
178
#ifndef __CYGWIN__
175
typedef	long key_t;
179
typedef	long key_t;
176
#endif
180
#endif
177
typedef _ssize_t ssize_t;
181
typedef _ssize_t ssize_t;
178
 
182
 
179
#ifndef __CYGWIN__
183
#if !defined(__CYGWIN__) && !defined(__rtems__)
180
#ifdef __MS_types__
184
#ifdef __MS_types__
181
typedef	char *	addr_t;
185
typedef	char *	addr_t;
182
typedef int mode_t;
186
typedef int mode_t;
183
#else
187
#else
184
#if defined (__sparc__) && !defined (__sparc_v9__)
188
#if defined (__sparc__) && !defined (__sparc_v9__)
185
#ifdef __svr4__
189
#ifdef __svr4__
186
typedef unsigned long mode_t;
190
typedef unsigned long mode_t;
187
#else
191
#else
188
typedef unsigned short mode_t;
192
typedef unsigned short mode_t;
189
#endif
193
#endif
190
#else
194
#else
191
typedef unsigned int mode_t _ST_INT32;
195
typedef unsigned int mode_t _ST_INT32;
192
#endif
196
#endif
193
#endif /* ! __MS_types__ */
197
#endif /* ! __MS_types__ */
194
#endif /*__CYGWIN__*/
198
#endif /*__CYGWIN__*/
195
 
199
 
196
typedef unsigned short nlink_t;
200
typedef unsigned short nlink_t;
197
 
201
 
198
/* We don't define fd_set and friends if we are compiling POSIX
202
/* We don't define fd_set and friends if we are compiling POSIX
199
   source, or if we have included (or may include as indicated
203
   source, or if we have included (or may include as indicated
200
   by __USE_W32_SOCKETS) the W32api winsock[2].h header which
204
   by __USE_W32_SOCKETS) the W32api winsock[2].h header which
201
   defines Windows versions of them.   Note that a program which
205
   defines Windows versions of them.   Note that a program which
202
   includes the W32api winsock[2].h header must know what it is doing;
206
   includes the W32api winsock[2].h header must know what it is doing;
203
   it must not call the cygwin32 select function.
207
   it must not call the cygwin32 select function.
204
*/
208
*/
205
# if !(defined (_POSIX_SOURCE) || defined (_WINSOCK_H) || defined (__USE_W32_SOCKETS)) 
209
# if !(defined (_POSIX_SOURCE) || defined (_WINSOCK_H) || defined (__USE_W32_SOCKETS)) 
206
#  define _SYS_TYPES_FD_SET
210
#  define _SYS_TYPES_FD_SET
207
#  define	NBBY	8		/* number of bits in a byte */
211
#  define	NBBY	8		/* number of bits in a byte */
208
/*
212
/*
209
 * Select uses bit masks of file descriptors in longs.
213
 * Select uses bit masks of file descriptors in longs.
210
 * These macros manipulate such bit fields (the filesystem macros use chars).
214
 * These macros manipulate such bit fields (the filesystem macros use chars).
211
 * FD_SETSIZE may be defined by the user, but the default here
215
 * FD_SETSIZE may be defined by the user, but the default here
212
 * should be >= NOFILE (param.h).
216
 * should be >= NOFILE (param.h).
213
 */
217
 */
214
#  ifndef	FD_SETSIZE
218
#  ifndef	FD_SETSIZE
215
#	define	FD_SETSIZE	64
219
#	define	FD_SETSIZE	64
216
#  endif
220
#  endif
217
 
221
 
218
typedef	long	fd_mask;
222
typedef	long	fd_mask;
219
#  define	NFDBITS	(sizeof (fd_mask) * NBBY)	/* bits per mask */
223
#  define	NFDBITS	(sizeof (fd_mask) * NBBY)	/* bits per mask */
220
#  ifndef	howmany
224
#  ifndef	howmany
221
#	define	howmany(x,y)	(((x)+((y)-1))/(y))
225
#	define	howmany(x,y)	(((x)+((y)-1))/(y))
222
#  endif
226
#  endif
223
 
227
 
224
/* We use a macro for fd_set so that including Sockets.h afterwards
228
/* We use a macro for fd_set so that including Sockets.h afterwards
225
   can work.  */
229
   can work.  */
226
typedef	struct _types_fd_set {
230
typedef	struct _types_fd_set {
227
	fd_mask	fds_bits[howmany(FD_SETSIZE, NFDBITS)];
231
	fd_mask	fds_bits[howmany(FD_SETSIZE, NFDBITS)];
228
} _types_fd_set;
232
} _types_fd_set;
229
 
233
 
230
#define fd_set _types_fd_set
234
#define fd_set _types_fd_set
231
 
235
 
232
#  define	FD_SET(n, p)	((p)->fds_bits[(n)/NFDBITS] |= (1L << ((n) % NFDBITS)))
236
#  define	FD_SET(n, p)	((p)->fds_bits[(n)/NFDBITS] |= (1L << ((n) % NFDBITS)))
233
#  define	FD_CLR(n, p)	((p)->fds_bits[(n)/NFDBITS] &= ~(1L << ((n) % NFDBITS)))
237
#  define	FD_CLR(n, p)	((p)->fds_bits[(n)/NFDBITS] &= ~(1L << ((n) % NFDBITS)))
234
#  define	FD_ISSET(n, p)	((p)->fds_bits[(n)/NFDBITS] & (1L << ((n) % NFDBITS)))
238
#  define	FD_ISSET(n, p)	((p)->fds_bits[(n)/NFDBITS] & (1L << ((n) % NFDBITS)))
235
#  define	FD_ZERO(p)	(__extension__ (void)({ \
239
#  define	FD_ZERO(p)	(__extension__ (void)({ \
236
     size_t __i; \
240
     size_t __i; \
237
     char *__tmp = (char *)p; \
241
     char *__tmp = (char *)p; \
238
     for (__i = 0; __i < sizeof (*(p)); ++__i) \
242
     for (__i = 0; __i < sizeof (*(p)); ++__i) \
239
       *__tmp++ = 0; \
243
       *__tmp++ = 0; \
240
}))
244
}))
241
 
245
 
242
# endif	/* !(defined (_POSIX_SOURCE) || defined (_WINSOCK_H) || defined (__USE_W32_SOCKETS)) */
246
# endif	/* !(defined (_POSIX_SOURCE) || defined (_WINSOCK_H) || defined (__USE_W32_SOCKETS)) */
243
 
247
 
244
#undef __MS_types__
248
#undef __MS_types__
245
#undef _ST_INT32
249
#undef _ST_INT32
246
 
250
 
247
 
251
 
248
#ifndef __clockid_t_defined
252
#ifndef __clockid_t_defined
249
typedef _CLOCKID_T_ clockid_t;
253
typedef _CLOCKID_T_ clockid_t;
250
#define __clockid_t_defined
254
#define __clockid_t_defined
251
#endif
255
#endif
252
 
256
 
253
#ifndef __timer_t_defined
257
#ifndef __timer_t_defined
254
typedef _TIMER_T_ timer_t;
258
typedef _TIMER_T_ timer_t;
255
#define __timer_t_defined
259
#define __timer_t_defined
256
#endif
260
#endif
257
 
261
 
258
typedef unsigned long useconds_t;
262
typedef unsigned long useconds_t;
259
typedef long suseconds_t;
263
typedef long suseconds_t;
260
 
264
 
261
#include 
265
#include 
262
 
266
 
263
 
267
 
264
/* Cygwin will probably never have full posix compliance due to little things
268
/* Cygwin will probably never have full posix compliance due to little things
265
 * like an inability to set the stackaddress. Cygwin is also using void *  
269
 * like an inability to set the stackaddress. Cygwin is also using void *  
266
 * pointers rather than structs to ensure maximum binary compatability with
270
 * pointers rather than structs to ensure maximum binary compatability with
267
 * previous releases.
271
 * previous releases.
268
 * This means that we don't use the types defined here, but rather in
272
 * This means that we don't use the types defined here, but rather in
269
 * 
273
 * 
270
 */
274
 */
271
#if defined(_POSIX_THREADS) && !defined(__CYGWIN__)
275
#if defined(_POSIX_THREADS) && !defined(__CYGWIN__)
272
 
276
 
273
#include 
277
#include 
274
 
278
 
275
/*
279
/*
276
 *  2.5 Primitive System Data Types,  P1003.1c/D10, p. 19.
280
 *  2.5 Primitive System Data Types,  P1003.1c/D10, p. 19.
277
 */
281
 */
278
 
282
 
279
#if defined(__XMK__)
283
#if defined(__XMK__)
280
typedef unsigned int pthread_t;          /* identify a thread */
284
typedef unsigned int pthread_t;          /* identify a thread */
281
#else
285
#else
282
typedef __uint32_t pthread_t;            /* identify a thread */
286
typedef __uint32_t pthread_t;            /* identify a thread */
283
#endif
287
#endif
284
 
288
 
285
/* P1003.1c/D10, p. 118-119 */
289
/* P1003.1c/D10, p. 118-119 */
286
#define PTHREAD_SCOPE_PROCESS 0
290
#define PTHREAD_SCOPE_PROCESS 0
287
#define PTHREAD_SCOPE_SYSTEM  1
291
#define PTHREAD_SCOPE_SYSTEM  1
288
 
292
 
289
/* P1003.1c/D10, p. 111 */
293
/* P1003.1c/D10, p. 111 */
290
#define PTHREAD_INHERIT_SCHED  1      /* scheduling policy and associated */
294
#define PTHREAD_INHERIT_SCHED  1      /* scheduling policy and associated */
291
                                      /*   attributes are inherited from */
295
                                      /*   attributes are inherited from */
292
                                      /*   the calling thread. */
296
                                      /*   the calling thread. */
293
#define PTHREAD_EXPLICIT_SCHED 2      /* set from provided attribute object */
297
#define PTHREAD_EXPLICIT_SCHED 2      /* set from provided attribute object */
294
 
298
 
295
/* P1003.1c/D10, p. 141 */
299
/* P1003.1c/D10, p. 141 */
296
#define PTHREAD_CREATE_DETACHED 0
300
#define PTHREAD_CREATE_DETACHED 0
297
#define PTHREAD_CREATE_JOINABLE  1
301
#define PTHREAD_CREATE_JOINABLE  1
298
 
302
 
299
#if defined(__XMK__) || defined(__rtems__)
303
#if defined(__XMK__) || defined(__rtems__)
300
/* The following defines are part of the X/Open System Interface (XSI). */
304
/* The following defines are part of the X/Open System Interface (XSI). */
301
 
305
 
302
/* This type of mutex does not detect deadlock. A thread attempting to relock this mutex without first unlocking 
306
/* This type of mutex does not detect deadlock. A thread attempting to relock this mutex without first unlocking 
303
 * it shall deadlock. Attempting to unlock a mutex locked by a different thread results in undefined behavior. 
307
 * it shall deadlock. Attempting to unlock a mutex locked by a different thread results in undefined behavior. 
304
 * Attempting to unlock an unlocked mutex results in undefined behavior. 
308
 * Attempting to unlock an unlocked mutex results in undefined behavior. 
305
 */
309
 */
306
#define PTHREAD_MUTEX_NORMAL  1
310
#define PTHREAD_MUTEX_NORMAL  1
307
 
311
 
308
/* 
312
/* 
309
 * This type of mutex provides error checking. A thread attempting to relock this mutex without first unlocking 
313
 * This type of mutex provides error checking. A thread attempting to relock this mutex without first unlocking 
310
 * it shall return with an error. A thread attempting to unlock a mutex which another thread has locked shall return 
314
 * it shall return with an error. A thread attempting to unlock a mutex which another thread has locked shall return 
311
 * with an error. A thread attempting to unlock an unlocked mutex shall return with an error. 
315
 * with an error. A thread attempting to unlock an unlocked mutex shall return with an error. 
312
 */
316
 */
313
#define PTHREAD_MUTEX_ERRORCHECK  2 
317
#define PTHREAD_MUTEX_ERRORCHECK  2 
314
 
318
 
315
/* A thread attempting to relock this mutex without first unlocking it shall succeed in locking the mutex. 
319
/* A thread attempting to relock this mutex without first unlocking it shall succeed in locking the mutex. 
316
 * The relocking deadlock which can occur with mutexes of type PTHREAD_MUTEX_NORMAL cannot occur with this type of mutex. 
320
 * The relocking deadlock which can occur with mutexes of type PTHREAD_MUTEX_NORMAL cannot occur with this type of mutex. 
317
 * Multiple locks of this mutex shall require the same number of unlocks to release the mutex before another thread can 
321
 * Multiple locks of this mutex shall require the same number of unlocks to release the mutex before another thread can 
318
 * acquire the mutex. A thread attempting to unlock a mutex which another thread has locked shall return with an error. 
322
 * acquire the mutex. A thread attempting to unlock a mutex which another thread has locked shall return with an error. 
319
 * A thread attempting to unlock an unlocked mutex shall return with an error. 
323
 * A thread attempting to unlock an unlocked mutex shall return with an error. 
320
 */
324
 */
321
#define PTHREAD_MUTEX_RECURSIVE  3
325
#define PTHREAD_MUTEX_RECURSIVE  3
322
 
326
 
323
/* Attempting to recursively lock a mutex of this type results in undefined behavior. Attempting to unlock a 
327
/* Attempting to recursively lock a mutex of this type results in undefined behavior. Attempting to unlock a 
324
 * mutex of this type which was not locked by the calling thread results in undefined behavior. Attempting to 
328
 * mutex of this type which was not locked by the calling thread results in undefined behavior. Attempting to 
325
 * unlock a mutex of this type which is not locked results in undefined behavior. An implementation may map this 
329
 * unlock a mutex of this type which is not locked results in undefined behavior. An implementation may map this 
326
 * mutex to one of the other mutex types.
330
 * mutex to one of the other mutex types.
327
 */
331
 */
328
#define PTHREAD_MUTEX_DEFAULT  4 
332
#define PTHREAD_MUTEX_DEFAULT  4 
329
 
333
 
330
#endif /* defined(__XMK__) || defined(__rtems__) */
334
#endif /* defined(__XMK__) || defined(__rtems__) */
331
 
335
 
332
#if defined(__XMK__)
336
#if defined(__XMK__)
333
typedef struct pthread_attr_s {
337
typedef struct pthread_attr_s {
334
  int contentionscope;
338
  int contentionscope;
335
  struct sched_param schedparam;
339
  struct sched_param schedparam;
336
  int  detachstate;
340
  int  detachstate;
337
  void *stackaddr;
341
  void *stackaddr;
338
  size_t stacksize;
342
  size_t stacksize;
339
} pthread_attr_t;
343
} pthread_attr_t;
340
 
344
 
341
#define PTHREAD_STACK_MIN       200
345
#define PTHREAD_STACK_MIN       200
342
 
346
 
343
#else /* !defined(__XMK__) */
347
#else /* !defined(__XMK__) */
344
typedef struct {
348
typedef struct {
345
  int is_initialized;
349
  int is_initialized;
346
  void *stackaddr;
350
  void *stackaddr;
347
  int stacksize;
351
  int stacksize;
348
  int contentionscope;
352
  int contentionscope;
349
  int inheritsched;
353
  int inheritsched;
350
  int schedpolicy;
354
  int schedpolicy;
351
  struct sched_param schedparam;
355
  struct sched_param schedparam;
-
 
356
#if defined(__rtems__)
-
 
357
  size_t guardsize;
-
 
358
#endif
352
 
359
 
353
  /* P1003.4b/D8, p. 54 adds cputime_clock_allowed attribute.  */
360
  /* P1003.4b/D8, p. 54 adds cputime_clock_allowed attribute.  */
354
#if defined(_POSIX_THREAD_CPUTIME)
361
#if defined(_POSIX_THREAD_CPUTIME)
355
  int  cputime_clock_allowed;  /* see time.h */
362
  int  cputime_clock_allowed;  /* see time.h */
356
#endif
363
#endif
357
  int  detachstate;
364
  int  detachstate;
358
 
365
 
359
} pthread_attr_t;
366
} pthread_attr_t;
360
 
367
 
361
#endif /* !defined(__XMK__) */
368
#endif /* !defined(__XMK__) */
362
 
369
 
363
#if defined(_POSIX_THREAD_PROCESS_SHARED)
370
#if defined(_POSIX_THREAD_PROCESS_SHARED)
364
/* NOTE: P1003.1c/D10, p. 81 defines following values for process_shared.  */
371
/* NOTE: P1003.1c/D10, p. 81 defines following values for process_shared.  */
365
 
372
 
366
#define PTHREAD_PROCESS_PRIVATE 0 /* visible within only the creating process */
373
#define PTHREAD_PROCESS_PRIVATE 0 /* visible within only the creating process */
367
#define PTHREAD_PROCESS_SHARED  1 /* visible too all processes with access to */
374
#define PTHREAD_PROCESS_SHARED  1 /* visible too all processes with access to */
368
                                  /*   the memory where the resource is */
375
                                  /*   the memory where the resource is */
369
                                  /*   located */
376
                                  /*   located */
370
#endif
377
#endif
371
 
378
 
372
#if defined(_POSIX_THREAD_PRIO_PROTECT)
379
#if defined(_POSIX_THREAD_PRIO_PROTECT)
373
/* Mutexes */
380
/* Mutexes */
374
 
381
 
375
/* Values for blocking protocol. */
382
/* Values for blocking protocol. */
376
 
383
 
377
#define PTHREAD_PRIO_NONE    0
384
#define PTHREAD_PRIO_NONE    0
378
#define PTHREAD_PRIO_INHERIT 1
385
#define PTHREAD_PRIO_INHERIT 1
379
#define PTHREAD_PRIO_PROTECT 2
386
#define PTHREAD_PRIO_PROTECT 2
380
#endif
387
#endif
381
 
388
 
382
#if defined(_UNIX98_THREAD_MUTEX_ATTRIBUTES)
389
#if defined(_UNIX98_THREAD_MUTEX_ATTRIBUTES)
383
 
390
 
384
/* Values for mutex type */
391
/* Values for mutex type */
385
 
392
 
386
#define PTHREAD_MUTEX_NORMAL     0
393
#define PTHREAD_MUTEX_NORMAL     0
387
#define PTHREAD_MUTEX_RECURSIVE  1
394
#define PTHREAD_MUTEX_RECURSIVE  1
388
#define PTHREAD_MUTEX_ERRORCHECK 2
395
#define PTHREAD_MUTEX_ERRORCHECK 2
389
#define PTHREAD_MUTEX_DEFAULT    3
396
#define PTHREAD_MUTEX_DEFAULT    3
390
 
397
 
391
#endif
398
#endif
392
 
399
 
393
#if defined(__XMK__)
400
#if defined(__XMK__)
394
typedef unsigned int pthread_mutex_t;    /* identify a mutex */
401
typedef unsigned int pthread_mutex_t;    /* identify a mutex */
395
 
402
 
396
typedef struct {
403
typedef struct {
397
  int type;
404
  int type;
398
} pthread_mutexattr_t;
405
} pthread_mutexattr_t;
399
 
406
 
400
#else /* !defined(__XMK__) */
407
#else /* !defined(__XMK__) */
401
typedef __uint32_t pthread_mutex_t;      /* identify a mutex */
408
typedef __uint32_t pthread_mutex_t;      /* identify a mutex */
402
 
409
 
403
typedef struct {
410
typedef struct {
404
  int   is_initialized;
411
  int   is_initialized;
405
#if defined(_POSIX_THREAD_PROCESS_SHARED)
412
#if defined(_POSIX_THREAD_PROCESS_SHARED)
406
  int   process_shared;  /* allow mutex to be shared amongst processes */
413
  int   process_shared;  /* allow mutex to be shared amongst processes */
407
#endif
414
#endif
408
#if defined(_POSIX_THREAD_PRIO_PROTECT)
415
#if defined(_POSIX_THREAD_PRIO_PROTECT)
409
  int   prio_ceiling;
416
  int   prio_ceiling;
410
  int   protocol;
417
  int   protocol;
411
#endif
418
#endif
412
#if defined(_UNIX98_THREAD_MUTEX_ATTRIBUTES)
419
#if defined(_UNIX98_THREAD_MUTEX_ATTRIBUTES)
413
  int type;
420
  int type;
414
#endif
421
#endif
415
  int   recursive;
422
  int   recursive;
416
} pthread_mutexattr_t;
423
} pthread_mutexattr_t;
417
#endif /* !defined(__XMK__) */
424
#endif /* !defined(__XMK__) */
418
 
425
 
419
/* Condition Variables */
426
/* Condition Variables */
420
 
427
 
421
typedef __uint32_t pthread_cond_t;       /* identify a condition variable */
428
typedef __uint32_t pthread_cond_t;       /* identify a condition variable */
422
 
429
 
423
typedef struct {
430
typedef struct {
424
  int   is_initialized;
431
  int   is_initialized;
425
#if defined(_POSIX_THREAD_PROCESS_SHARED)
432
#if defined(_POSIX_THREAD_PROCESS_SHARED)
426
  int   process_shared;       /* allow this to be shared amongst processes */
433
  int   process_shared;       /* allow this to be shared amongst processes */
427
#endif
434
#endif
428
} pthread_condattr_t;         /* a condition attribute object */
435
} pthread_condattr_t;         /* a condition attribute object */
429
 
436
 
430
/* Keys */
437
/* Keys */
431
 
438
 
432
typedef __uint32_t pthread_key_t;        /* thread-specific data keys */
439
typedef __uint32_t pthread_key_t;        /* thread-specific data keys */
433
 
440
 
434
typedef struct {
441
typedef struct {
435
  int   is_initialized;  /* is this structure initialized? */
442
  int   is_initialized;  /* is this structure initialized? */
436
  int   init_executed;   /* has the initialization routine been run? */
443
  int   init_executed;   /* has the initialization routine been run? */
437
} pthread_once_t;       /* dynamic package initialization */
444
} pthread_once_t;       /* dynamic package initialization */
438
#else
445
#else
439
#if defined (__CYGWIN__)
446
#if defined (__CYGWIN__)
440
#include 
447
#include 
441
#endif
448
#endif
442
#endif /* defined(_POSIX_THREADS) */
449
#endif /* defined(_POSIX_THREADS) */
443
 
450
 
444
/* POSIX Barrier Types */
451
/* POSIX Barrier Types */
445
 
452
 
446
#if defined(_POSIX_BARRIERS)
453
#if defined(_POSIX_BARRIERS)
447
typedef __uint32_t pthread_barrier_t;        /* POSIX Barrier Object */
454
typedef __uint32_t pthread_barrier_t;        /* POSIX Barrier Object */
448
typedef struct {
455
typedef struct {
449
  int   is_initialized;  /* is this structure initialized? */
456
  int   is_initialized;  /* is this structure initialized? */
450
#if defined(_POSIX_THREAD_PROCESS_SHARED)
457
#if defined(_POSIX_THREAD_PROCESS_SHARED)
451
  int   process_shared;       /* allow this to be shared amongst processes */
458
  int   process_shared;       /* allow this to be shared amongst processes */
452
#endif
459
#endif
453
} pthread_barrierattr_t;
460
} pthread_barrierattr_t;
454
#endif /* defined(_POSIX_BARRIERS) */
461
#endif /* defined(_POSIX_BARRIERS) */
455
 
462
 
456
/* POSIX Spin Lock Types */
463
/* POSIX Spin Lock Types */
457
 
464
 
458
#if defined(_POSIX_SPIN_LOCKS)
465
#if defined(_POSIX_SPIN_LOCKS)
459
typedef __uint32_t pthread_spinlock_t;        /* POSIX Spin Lock Object */
466
typedef __uint32_t pthread_spinlock_t;        /* POSIX Spin Lock Object */
460
#endif /* defined(_POSIX_SPIN_LOCKS) */
467
#endif /* defined(_POSIX_SPIN_LOCKS) */
461
 
468
 
462
/* POSIX Reader/Writer Lock Types */
469
/* POSIX Reader/Writer Lock Types */
463
 
470
 
464
#if !defined (__CYGWIN__)
471
#if !defined (__CYGWIN__)
465
#if defined(_POSIX_READER_WRITER_LOCKS)
472
#if defined(_POSIX_READER_WRITER_LOCKS)
466
typedef __uint32_t pthread_rwlock_t;         /* POSIX RWLock Object */
473
typedef __uint32_t pthread_rwlock_t;         /* POSIX RWLock Object */
467
typedef struct {
474
typedef struct {
468
  int   is_initialized;       /* is this structure initialized? */
475
  int   is_initialized;       /* is this structure initialized? */
469
#if defined(_POSIX_THREAD_PROCESS_SHARED)
476
#if defined(_POSIX_THREAD_PROCESS_SHARED)
470
  int   process_shared;       /* allow this to be shared amongst processes */
477
  int   process_shared;       /* allow this to be shared amongst processes */
471
#endif
478
#endif
472
} pthread_rwlockattr_t;
479
} pthread_rwlockattr_t;
473
#endif /* defined(_POSIX_READER_WRITER_LOCKS) */
480
#endif /* defined(_POSIX_READER_WRITER_LOCKS) */
474
#endif /* __CYGWIN__ */
481
#endif /* __CYGWIN__ */
475
 
482
 
476
#endif  /* !__need_inttypes */
483
#endif  /* !__need_inttypes */
477
 
484
 
478
#undef __need_inttypes
485
#undef __need_inttypes
479
 
486
 
480
#endif	/* _SYS_TYPES_H */
487
#endif	/* _SYS_TYPES_H */